Re: Password login code



I tried it there and I'm still getting the "Invalid argument" error. Is
something else awry?:

Private Sub cmdLogin_Click()
On Error GoTo Err_cmdLogin_Click

Dim rs As Recordset
Dim strUser As String
Dim strPassword As String

txtName.SetFocus
strUser = txtUserNm
txtPassword.SetFocus
strPassword = txtPassword

If Not IsNull(Me.txtName) And Not IsNull(Me.txtPassword) Then
Set rs = CurrentDb.OpenRecordset("Select * from tblLogin where Name = '" &
strUser & "' And Password = '" & strPassword & "'", dbOpenSnapshot)

If rs.EOF Then
DoCmd.OpenForm "Main"
Else
MsgBox "In Correct"
End If
End If

Exit_cmdLogin_Click:
Exit Sub

Err_cmdLogin_Click:
MsgBox Err.Description
Resume Exit_cmdLogin_Click

End Sub



"Douglas J. Steele" wrote:

It goes between the existing End If statement and the Exit_cmdLogin_Click:
line.

A single quote in code means everything after the quote is a comment.
However, there's really no need to include it in this case.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Caledonia" <Caledonia@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:69068550-814D-4302-897F-C3327290CC98@xxxxxxxxxxxxxxxx
Thanks for responding! Stupid question -- where do I put the "End If'"?
I've tried at the end of the first If statement, after the second If
statement, before the "End Sub" -- I either get "Invalid syntax" or
"Invalid
argument". And is there actually a single quote after the "End If"?

"Douglas J. Steele" wrote:

You've got two If statements, but only one End If

If Not IsNull(Me.txtName) And Not IsNull(Me.txtPassword) Then
Set rs = CurrentDb.OpenRecordset("Select * from tblLogin where Name =
'" &
strUser & "' And Password = '" & strPassword & "'", dbOpenSnapshot)

If rs.EOF Then
DoCmd.OpenForm "Main"
Else
MsgBox "In Correct"
End If

End If ' <== missing


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


"Caledonia" <Caledonia@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:1515E5BF-89AB-4C88-A3C3-9EB1A987F708@xxxxxxxxxxxxxxxx
I pulled this code from a past thread in 2005 by G Gill and Doug Steele,
and
I modified it to match my table fields. I keep getting an error "Block
If
without End If". I've tried putting an "End If" after the "If Not
IsNull."
statement, but then I get "Invalid syntax". Where should the "End If"
statement go?

Private Sub cmdLogin_Click()
On Error GoTo Err_cmdLogin_Click

Dim rs As Recordset
Dim strUser As String
Dim strPassword As String

txtName.SetFocus
strUser = txtUserNm
txtPassword.SetFocus
strPassword = txtPassword

If Not IsNull(Me.txtName) And Not IsNull(Me.txtPassword) Then
Set rs = CurrentDb.OpenRecordset("Select * from tblLogin where Name =
'" &
strUser & "' And Password = '" & strPassword & "'", dbOpenSnapshot)


If rs.EOF Then
DoCmd.OpenForm "Main"
Else
MsgBox "In Correct"
End If

Exit_cmdLogin_Click:
Exit Sub

Err_cmdLogin_Click:
MsgBox Err.Description
Resume Exit_cmdLogin_Click

End Sub










.