View Single Post
  #1 (permalink)  
Old May 22nd, 2006, 08:36 AM
Iashia06 Iashia06 is offline
Registered User
 
Join Date: Apr 2006
Location: Springfield, MA, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object Variable or With Block Variable Not Set

Hi,

I've created a login form based on a Users table. My intention is for the user to type in their username/password and the VBA is supposed to loop through the table until that username/password record is reached. Once the username/password is verified, the app is supposed to Open an Approval form. However, I keep getting an error message. Can some please help. The code is as follows:

    Dim rs As ADODB.Recordset
    rs.ActiveConnection =
    "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=\\intraweb\" & _
    "CapitalProjects$\CapitalProjects.mdb;"

    Set rs = New ADODB.Recordset
    rs.Open "SELECT * FROM Users;"
    rs.MoveFirst
Do
    Debug.Print rs.Fields(0), rs.Fields(1)
    If rs.EOF = True Or rs.BOF = True Then
        Exit Sub
    End If
    If Not txtUserName.Value > "" Or
    (Not txtPassword.Value > "") Then
        MsgBox "You cannot enter a blank
               Username/Password. Try again."
        txtUserName.SetFocus
        Exit Sub
    ElseIf UserName = txtUserName.Value And
           Password = txtPassword.Value Then
           MsgBox "You are logged in as " & UserName
           stDocName = "Approval"
           stDocName2 = "Login"
           DoCmd.Close acForm, "Login"
           DoCmd.OpenForm stDocName, , , stLinkCriteria
           Exit Sub
    End If
    rs.MoveNext
Loop
    If txtUserName.Value <> UserName Or
       txtPassword.Value <> Password Then
       MsgBox "You are not authorized to access this form!"
       MsgBox UserName
       stDocName = "Selection"
       stDocName2 = "Login"
       DoCmd.Close acForm, "Login"
       DoCmd.OpenForm stDocName, , , stLinkCriteria
       Exit Sub
    End If
    rs.Close
    Set rs = Nothing