Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare Query Results to Dialog Box Input 1

Status
Not open for further replies.

0212

Technical User
Apr 2, 2003
115
0
0
US
Hi, all! I have a dialog box where the user inputs a username and password. Then I attach code to the OK Command Button (See Below). I also have a table with valid Usernames and passwords. Finally, I created a query that I pass the dialog box parameters to to check if the username and password is in the table. If it is, I want to open the main menu of the application so that the user can run the application. If the password and userid are not in the table, then a message box will open stating that they need to try again. I the error message 'Object Required'. Any ideas? Thanks a whole lot in advance!!


Private Sub OK_Click()
Dim stDocName As String
stDocName = "Qry_Login_PE"
DoCmd.OpenQuery stDocName, acViewNormal, acEdit
If Qry_Login_PE.PELastName.Value = Me.User_ID And Qry_Login_PE.Password.Value = Me.Pass_word Then
DoCmd.OpenForm FrmMainMenu, acNormal, , acEdit
Else
MsgBox "Incorrect UserID or Password, please try again"
End If
End Sub
 
Have a look at the DLookUp function.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks, PMV, for you suggestions. However, now I cannot get the Dlookup function to work properly using input from the dialog box. It seems to ignore the variable. The below code results in Null for any input of Me.User_ID. Can you or anyone else help? Thanks!


Private Sub OK_Click()
Dim stDocName As String
Dim strUserID As Variant
Dim strPassword As Variant
Dim stwhere As String
stwhere = Me.User_ID
Me.Visible = False
stDocName = "Qry_Login_PE"


strUserID = DLookup("[UserID]", "LoginTable", "[UserID] = 'Strwhere'")
strPassword = DLookup("[Password]", "LoginTable", "[Password] = 'Me!Pass_word'")

If IsNull(strUserID) Or IsNull(strPassword) Then
MsgBox "Incorrect UserID or Password, please try again"
Else
DoCmd.OpenForm "FrmMainMenu", acNormal, , acEdit

End If

End Sub
 
You may try this:
Code:
Private Sub OK_Click()
Dim strPassword As Variant
strPassword = DLookup("Password", "LoginTable", "UserID='" & Me!User_ID & "'")
If IsNull(strPassword) Or Trim(strPassword & "") <> Trim(Me!Pass_word & "") Then
    MsgBox "Incorrect UserID or Password, please try again"
Else
    DoCmd.OpenForm "FrmMainMenu", acNormal, , acEdit
    Me.Visible = False
End If
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV, thank you! I can't seem to understand the punctuation. Do you know any resources that may help? Thanks again!

Jim.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top