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










.



Relevant Pages

  • photo display fumbles
    ... Dim ysnSaveButtonClicked As Boolean ... Private Sub Command68_Click ... On Error GoTo ErrHandler ... '" Dim Cancel As Integer ...
    (microsoft.public.access.reports)
  • RE: Unexplained run-time error 3021
    ... Private Sub Form_Current ... On Error GoTo err_Form_Current ... Dim Count As Integer, Position As Integer ... to suppress the ‘no current record’ error messages when navigating through ...
    (microsoft.public.access.formscoding)
  • Update or CancelUpdate without AddNew or Edit. (Error 3020)
    ... Dim bLoad As Boolean ... Private Sub DESCRIPTION_KeyPress ... On Error GoTo ErrorCondition ... MsgBox Err.DESCRIPTION, vbCritical, "DESCRIPTION_KeyPress" ...
    (microsoft.public.access.modulesdaovba)
  • Re: access 2003 crashing
    ... On Error GoTo Err_Button25_Click ... As String, MySQL7 As String, cp As Currency, D As Currency ... Dim Precharges As Currency, Answer As Date, Answer1 As String, FeeReg ... Private Sub DoCalculation ...
    (microsoft.public.access.formscoding)
  • Adding a second picture to same record
    ... that I made was to add a second picture at my daughter's insistance. ... On Error GoTo cmdAddImage1_Err ... Dim strFilter As String ... Private Sub cmdDeleteImage1_Click ...
    (comp.databases.ms-access)