G
Guest
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
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