won't let you into form if textbox entry not found in table

P

p-rat

From my switchboard I have a selection "Enter Field Ticket
Information". When clicked I would like a dialog box or some form pop-
up and ask "What location?". The end-user would then type in their
location.

There is a table that I have called UserLocation. In this table I have
a field User and a field Location. The User field is their logon. It's
the GetUserName script. If the location the end-user types in the
dialog box or form = location in table and the user = user for that
location then I want the data entry form to pop-up for the end-user to
enter in their Field Ticket information. If the location they type in
doesn't match or the UserName doesn't equal that of the location then
I want a textbox to pop-up saying "sorry you are not authorized to
enter information for this location".

Would anyone know how I can make this work? Any help would be
appreciated. Thanks.
 
E

ErezM via AccessMonster.com

hi
set the switchboard option to open the data entry form (the final destination)

you will check for the user and location, when that form will open (either by
the switchboard or directly from the database window). in the data entry
form's open event, write:
Me.Tag = "x" (this will be used as a flag for successful match)

DoCmd.OpenForm "frmIdentify", , , , , acDialog (this is the location/user
form, and it has to be modal and opened as dialog to hold the code from
running until it's closed)

If Me.Tag <> "good" Then Cancel = 1 (the location/user from will set this
form's tag property to "good" if the user selected the right location,
otherwise the form will close itself)

now add a new form called "frmIdentify"
add a textbox named txtLocation (or combobox to select the location...) and a
command button
on the command button's click event, write:

If DCount("User", "UserLocation", "User='" & GetUserName() & "' And
Location='" & txtLocation & "'") = 0 Then
MsgBox "sorry you are not authorized to enter information for this
location"
Else
Forms!frmDataEntry.Tag = "good"
End If
DoCmd.Close acForm, "frmIdentify"

the if statement checks if there is a record with the user from GetUserName
function and the location entered in txtLocation textbox.

if so, the tag for the calling form (the data entry form) is set to "good",
and if not a messagebox states that the user and location doesnt match

then from closes, which then executes the next line of code on the main form,
who checks if the tag equale "good", and if not, cancels the form's opening

good luck
Erez
 
P

p-rat

Thanks for your help. I did what you said and it works great. I
appreciate it. One other thing I would like to do and have done on
other forms other than 'Modal' is to have the value of , in our
example, "Location" on the modal form "frmIdentify" to become the
default value on the data entry form (along with a textbox on the
modal form for date). this is a request from the end users to speed up
their entry (they don't have to keep entering in location if they have
a stack of tickets to enter for the same location). let me know if
this can be done. thanks.
 
E

ErezM via AccessMonster.com

hi again
since we're already using the tag property, you can use it to save the
location and add it on every new record:
change the code to on the main form to:

if me.tag="x" then cancel=1 (there is no location, so the user failed)

and on frmIdentify to:

If DCount("User", "UserLocation", "User='" & GetUserName() & "' And
Location='" & txtLocation & "'") = 0 Then
MsgBox "sorry you are not authorized to enter information for this
location"
Else
Forms!frmDataEntry.Tag = txtLocation
End If
DoCmd.Close acForm, "frmIdentify"

now that you have the user's location in the tag property, use the
BeforeInsert event of the form to update the location to the tag property's
value:

Location=me.tag

this will insert the location every time the user adds a new record,
make sure the first control in the tab order is the other control (not the
location, cause that one is inserted by code) or the user wont understand
what is going on

good luck again
Erez
p-rat said:
Thanks for your help. I did what you said and it works great. I
appreciate it. One other thing I would like to do and have done on
other forms other than 'Modal' is to have the value of , in our
example, "Location" on the modal form "frmIdentify" to become the
default value on the data entry form (along with a textbox on the
modal form for date). this is a request from the end users to speed up
their entry (they don't have to keep entering in location if they have
a stack of tickets to enter for the same location). let me know if
this can be done. thanks.
hi
set the switchboard option to open the data entry form (the final destination)
[quoted text clipped - 62 lines]
- Show quoted text -
 
P

p-rat

How about another textbox on the modal form ("frmIdentify") for the
date. How can I have that as a default value on the main form? Thanks.
Your changes work without a problem. Thanks again for your help.


hi again
since we're already using the tag property, you can use it to save the
location and add it on every new record:
change the code to on the main form to:

if me.tag="x" then cancel=1 (there is no location, so the user failed)

and on frmIdentify to:

If DCount("User", "UserLocation", "User='" & GetUserName() & "' And
Location='" & txtLocation & "'") = 0 Then
   MsgBox "sorry you are not authorized to enter information for this
location"
Else
   Forms!frmDataEntry.Tag = txtLocation
End If
DoCmd.Close acForm, "frmIdentify"

now that you have the user's location in the tag property, use the
BeforeInsert event of the form to update the location to the tag property's
value:

Location=me.tag

this will insert the location every time the user adds a new record,
make sure the first control in the tab order is the other control (not the
location, cause that one is inserted by code) or the user wont understand
what is going on

good luck again
Erez





p-rat said:
Thanks for your help. I did what you said and it works great. I
appreciate it. One other thing I would like to do and have done on
other forms other than 'Modal' is to have the value of , in our
example, "Location" on the modal form "frmIdentify" to become the
default value on the data entry form (along with a textbox on the
modal form for date). this is a request from the end users to speed up
their entry (they don't have to keep entering in location if they have
a stack of tickets to enter for the same location). let me know if
this can be done. thanks.
hi
set the switchboard option to open the data entry form (the final destination)
[quoted text clipped - 62 lines]
- Show quoted text -

--
May all beings be happy.

http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/200903/1- Hide quoted text -

- Show quoted text -
 
E

ErezM via AccessMonster.com

hi
the form's tag property is taken, but every control on the (main) form has a
tag property which is waiting to be used. when i need to pass more than one
value, i usually take another route, but it's a bit long to write down here,
so the easiest way is to use, say, the date textbox itself on the main form
from the modal form you set along with

Forms!frmDataEntry.Tag = txtLocation

something like this

Forms!frmDataEntry!txtDate.Tag = txtDefaultDate

so the form's tag will hold the location (and be used to test for success)
and the date texbox tag will hold the date, and you will set them both on the
same event (before insert)

good luck

p-rat said:
How about another textbox on the modal form ("frmIdentify") for the
date. How can I have that as a default value on the main form? Thanks.
Your changes work without a problem. Thanks again for your help.
hi again
since we're already using the tag property, you can use it to save the
[quoted text clipped - 50 lines]
- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top