Two Fields matched

L

learning_codes

Hi,

I'm create a list of userid and name in a table. Both fields are
primary key. I design a form and create two unbound box. This are
for enter UserID and Name to check if there is a match before going to
the form or msgbox saying, "please contact the contact person"

Form:
1st Unbound box: txtUserID
2nd Unbound box: txtName

------------- create a button "Click"

Table:
UserID
Name

'************************************

If Me.txtUserID = [Table1].[UserID] and Me.txtName = [Table1].[Name]
then
.....
.....
go to form
Else
MsgBox "Please contact Administrator"
Exit Sub
End if

'***********************************

I try many times but I don't know if I did the right thing.

I would be much appreciated of your help.
Thanks
 
A

Al Campagna

First, it's usual to just use the UserName as the Dlookup "where" value,
to see if the UserID is correct, for that UserName.
(The If/Dlookup/Then are all on one line)

If Dlookup("[UserID]","tblYourTableName", "UserName = '" & UserName &
"'") = Me.UserID Then
'msgbox here to say "Failed.. etc"
Else
'code here to open the form
End If

Note: I'll expand the quote marks in the Dlookup so you can see more
clearly... but you need to remove the spaces in your actual code.

If IsNull(Dlookup("[UserID]","tblYourTableName", "UserName = ' " & UserName
& " ' "))
--
hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 
D

dcsergent

Hi,

I'm create a list of userid and name in a table. Both fields are
primary key. I design a form and create two unbound box. This are
for enter UserID and Name to check if there is a match before going to
the form or msgbox saying, "please contact the contact person"

Form:
1st Unbound box: txtUserID
2nd Unbound box: txtName

------------- create a button "Click"

Table:
UserID
Name

'************************************

If Me.txtUserID = [Table1].[UserID] and Me.txtName = [Table1].[Name]
then
.....
.....
go to form
Else
MsgBox "Please contact Administrator"
Exit Sub
End if

'***********************************

I try many times but I don't know if I did the right thing.

I would be much appreciated of your help.
Thanks

FYI: You can do the following all in code.
Have you considered creating a query and comparing the two fields to
each other? Here is a two part possibility:

Part I
1. Create a query in design view.
2. Add the table that contains your fields. In this example, we will
call it tblNames
3. Add the fields UserID and Name
4. Add another field in the query and for the name, type:
CheckNames:IIF([UserID] = [Name],"Mismatch","Good")
5. Save the query as qryNameCheck
6. Run the query to check for errors. (If there is an error, write
down exactly what the message box displays and you can reply to the
group, but reply to me as well.)
7. If there are no errors, save the query and close it.
8. Create a form in design view and name it frmNameCheck and set it's
visible property to FALSE and set it's source to qryNameCheck.
9. Add a text box control and name it txtCheckNames
10. Make the source of the text box [CheckNames]

Part II
1. Now on the button that opens the original form, have it open this
new form.
2. After it opens the new form, check the value of the text box of the
hidden form.
3. If the text box' text = "Mismatch" then you can display the message
box and then close the form.
4. For the else part, you can open the form.
 

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