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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error 3075 when using login code 1

Status
Not open for further replies.

valgore

Technical User
Nov 12, 2008
180
US
im trying to make a log in form, and i keep getting "Run-time error '3075': Syntax error (missing operator) in query expression 'UCase(trim(User Name))='". i have made a table called UNP. it has two fields: User Name and Password. Im using Access 2007. here is my code
Code:
Private Sub Command12_Click()
'check for null User
    If IsNull(Trim(txtUser)) Then
        MsgBox "User Name required.", vbExclamation
        txtUser.SetFocus
        Exit Sub
    End If

    
    'check for null password
    If IsNull(Trim(txtPassword)) Then
        MsgBox "Password required.", vbExclamation
        txtPassword.SetFocus
        Exit Sub
    End If
    
    Dim tempRecordSet As Recordset, Password As String
    
    Set tempRecordSet = CurrentDb.OpenRecordset("select * from UNP where UCase(trim(User Name)) = '" & UCase(Trim(txtUser)) & "'")
    
        If tempRecordSet.RecordCount <> 0 Then
        Password = UCase(Trim(tempRecordSet("UNP.Password")))
    End If
    
      tempRecordSet.Close
    Set tempRecordSet = Nothing
    
    If Password <> UCase(Trim(txtPassword)) Then
       MsgBox "Access Denied", vbExclamation
    Else
         MsgBox "Access Granted", vbExclamation
    End If
    txtPassword = Empty
End Sub

The code works up until
Set tempRecordSet = CurrentDb.OpenRecordset("select * from UNP where UCase(trim(User Name)) = '" & UCase(Trim(txtUser)) & "'")

Can anyone help?

The second question i have is when i view my logon form in form view, and i select my user name from a drop down list, it inserts my password in the password box by itself. how do i stop this?

Thanks,
Valgore
 
So, after many re-try's, i FINALLY got it. thanks you everyone that helped. it was all a syntax issue with the forms.
Code:
Private Sub Command12_Click()
 
        If IsNull(Trim(Forms!LogonScreen!User)) Then
        MsgBox "User Name required.", vbExclamation
        Forms!LogonScreen!User.SetFocus
        Exit Sub
    End If
    
        If IsNull(Trim(Forms!LogonScreen!Password)) Then
        MsgBox "Password required.", vbExclamation
        Forms!LogonScreen!Password.SetFocus
        Exit Sub
    End If
    
      Dim tempRecordSet As Recordset, Password As String
    
      Set tempRecordSet = CurrentDb.OpenRecordset("select * from UNP where UCase(trim(UserName)) = '" & UCase(Trim(Forms!LogonScreen!User)) & "'")
    
        If tempRecordSet.RecordCount <> 0 Then
        Password = UCase(Trim(tempRecordSet("Password")))
        If Password = UCase(Trim(Forms!LogonScreen!Password)) Then
            MsgBox "Access Granted", vbExclamation
            Exit Sub
         End If
    End If
    
    tempRecordSet.Close
    Set tempRecordSet = Nothing
    
   MsgBox "Incorrect password", vbExclamation
    
   txtPassword = Empty
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top