I need help. Getting Compile error/Method or data not found!

Abouya

Registered User.
Local time
Yesterday, 16:31
Joined
Oct 11, 2016
Messages
88
i get another error in a different place: "Compile error: invalide use of property"

Private Sub Command1_Click()
Dim UserLevel As String
Dim TempPass As String
Dim ID As Integer
Dim TempLoginID As String

If IsNull(Me.txtLoginID) Then
MsgBox "Please Enter LoginID", vbInformation, "LoginID Required"
Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please Enter Your Password", vbInformation, "Password Required"
Me.txtPassword.SetFocus
Else
'process the job
If (IsNull(DLookup("[UserLogin]", "tblUser", "[UserLogin] ='" & Me.txtLoginID.Value & "' And password = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Invalid LoginID or Password"
Else
TempLoginID = Me.txtLoginID.Value
UserName = DLookup("UserName", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
UserLevel = DLookup("UserSecurity", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
TempPass = DLookup("Password", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
ID = DLookup("UserID", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
DoCmd.Close
If (TempPass = "password") Then
MsgBox "Please Change your Password", vbInformation, "New Password Required!"
DoCmd.OpenForm "ChangesNewPassword", , , "[UserID]=" & ID
Else
If UserLevel = "Admin" Then
'MsgBox "LoginID or Password Correct"
DoCmd.OpenForm "Navigation Form"
Form! [Navigation Form]![txtLogin] = TempLoginID
Form! [Navigation Form]![txtUser] = LoginID
Else
DoCmd.OpenForm "frmlRequisitionOrder"
End If
End If
End If
End If
End Sub
 
Last edited:
Do NOT use the .VALUE property, just use
Me.txtUserName
 
Do NOT use the .VALUE property, just use
Me.txtUserName

Still getting the same error even after getting rid or .Value!
 
Double check the spelling of txtUserName by using Intellisense. After typing Me. txtUserName should show in the drop down and even if it's there you can check to make sure it's not just a table field but a textbox by typing a period after it. If only Value shows up is only a table field. Other properties and methods, e.g., SetFocus should show up.
 
Double check the spelling of txtUserName by using Intellisense. After typing Me. txtUserName should show in the drop down and even if it's there you can check to make sure it's not just a table field but a textbox by typing a period after it. If only Value shows up is only a table field. Other properties and methods, e.g., SetFocus should show up.

I typed In me. txt but only txtLoginID and txtPassword showed up! how i can reference txtUserName ? it exist in a table called tblUser.
 
Double check the spelling of txtUserName by using Intellisense. After typing Me. txtUserName should show in the drop down and even if it's there you can check to make sure it's not just a table field but a textbox by typing a period after it. If only Value shows up is only a table field. Other properties and methods, e.g., SetFocus should show up.

I fixed few things and changed UserName to LoginID as it should be. now i get another error in a different place: "Compile error: invalide use of property"

Private Sub Command1_Click()
Dim UserLevel As String
Dim TempPass As String
Dim ID As Integer
Dim TempLoginID As String

If IsNull(Me.txtLoginID) Then
MsgBox "Please Enter LoginID", vbInformation, "LoginID Required"
Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please Enter Your Password", vbInformation, "Password Required"
Me.txtPassword.SetFocus
Else
'process the job
If (IsNull(DLookup("[UserLogin]", "tblUser", "[UserLogin] ='" & Me.txtLoginID.Value & "' And password = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Invalid LoginID or Password"
Else
TempLoginID = Me.txtLoginID.Value
UserName = DLookup("UserName", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
UserLevel = DLookup("UserSecurity", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
TempPass = DLookup("Password", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
ID = DLookup("UserID", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
DoCmd.Close
If (TempPass = "password") Then
MsgBox "Please Change your Password", vbInformation, "New Password Required!"
DoCmd.OpenForm "ChangesNewPassword", , , "[UserID]=" & ID
Else
If UserLevel = "Admin" Then
'MsgBox "LoginID or Password Correct"
DoCmd.OpenForm "Navigation Form"
Form! [Navigation Form]![txtLogin] = TempLoginID
Form! [Navigation Form]![txtUser] = LoginID
Else
DoCmd.OpenForm "frmlRequisitionOrder"
End If
End If
End If
End If
End Sub
 
If the value in txtUserName is in another table, a table that's not part of the record source of the form, you could use DLooKUp to get the value but what this doing

Code:
TempLoginID = Me.txtUserName

I don't see any place where TempLoginID is used.
 
If the value in txtUserName is in another table, a table that's not part of the record source of the form, you could use DLooKUp to get the value but what this doing

Code:
TempLoginID = Me.txtUserName

I don't see any place where TempLoginID is used.

TempLoginID is used as a temp to get UserName and keep it even after login. Can i privately send you the file?
 
Code:
Form! [Navigation Form]![txtLogin] = TempLoginID

Do you have a textbox name txtLogin on the main form. Typical this is a way used to store values so that they persist when switching tabs. Usually they are hidden.
 
Code:
Form! [Navigation Form]![txtLogin] = TempLoginID

Do you have a textbox name txtLogin on the main form. Typical this is a way used to store values so that they persist when switching tabs. Usually they are hidden.

yes i do, i have two text boxes one called txtLogin and the other txtUser.
 
It's the spaces that are causing the compile errors. Just change

Code:
Form! [Navigation Form]![txtLogin] = TempLoginID
Form! [Navigation Form]![txtUser] = UserName

to
Code:
Form![Navigation Form]![txtLogin] = TempLoginID
Form![Navigation Form]![txtUser] = UserName
 
For future posts please enclose code in code tags so that the indentation is preserved. To do this:

  1. Click on the Go Advance button
  2. Copy and paste the code as you've been doing
  3. Select the code
  4. Click on the pound sign (#) in the menu
 
It's the spaces that are causing the compile errors. Just change

Code:
[CODE]Form! [Navigation Form]![txtLogin] = TempLoginID
Form! [Navigation Form]![txtUser] = UserName

to
Code:
Form![Navigation Form]![txtLogin] = TempLoginID
Form![Navigation Form]![txtUser] = UserName

Works, however, now i get this error: In attached picture

Private Sub Command1_Click()
Dim UserLevel As String
Dim TempPass As String
Dim ID As Integer
Dim TempLoginID As String

If IsNull(Me.txtLoginID) Then
MsgBox "Please Enter LoginID", vbInformation, "LoginID Required"
Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please Enter Your Password", vbInformation, "Password Required"
Me.txtPassword.SetFocus
Else
'process the job
If (IsNull(DLookup("[UserLogin]", "tblUser", "[UserLogin] ='" & Me.txtLoginID.Value & "' And password = '" & Me.txtPassword.Value & "'"))) Then
MsgBox "Invalid LoginID or Password"
Else
TempLoginID = Me.txtLoginID.Value
UserName = DLookup("UserName", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
UserLevel = DLookup("UserSecurity", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
TempPass = DLookup("Password", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
ID = DLookup("UserID", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
DoCmd.Close
If (TempPass = "password") Then
MsgBox "Please Change your Password", vbInformation, "New Password Required!"
DoCmd.OpenForm "ChangesNewPassword", , , "[UserID]=" & ID
Else
If UserLevel = "Admin" Then
'MsgBox "LoginID or Password Correct"
DoCmd.OpenForm "Navigation Form"
Form![Navigation Form]![txtLogin] = TempLoginID
Form![Navigation Form]![txtUser] = UserName
Else
DoCmd.OpenForm "frmlRequisitionOrder"
End If
End If
End If
End If
End Sub[/CODE]
 
Last edited:
It's forms not form

Forms.[Navigation Form]![txtLogin] = TempLoginID
 
It's forms not form

Forms.[Navigation Form]![txtLogin] = TempLoginID

I just changed it and now i get another error 2465, access can't find the field 'txtLogin' referred to in your expression!

I do have two textboxes in main form txtLogin and txtUser.



Code:
Private Sub Command1_Click()
Dim UserLevel As String
Dim TempPass As String
Dim ID As Integer
Dim TempLoginID As String

If IsNull(Me.txtLoginID) Then
    MsgBox "Please Enter LoginID", vbInformation, "LoginID Required"
    Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtPassword) Then
    MsgBox "Please Enter Your Password", vbInformation, "Password Required"
    Me.txtPassword.SetFocus
Else
    'process the job
     If (IsNull(DLookup("[UserLogin]", "tblUser", "[UserLogin] ='" & Me.txtLoginID.Value & "' And password = '" & Me.txtPassword.Value & "'"))) Then
        MsgBox "Invalid LoginID or Password"
    Else
        TempLoginID = Me.txtLoginID.Value
        UserName = DLookup("UserName", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
        UserLevel = DLookup("UserSecurity", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
        TempPass = DLookup("Password", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
        ID = DLookup("UserID", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'")
        DoCmd.Close
            If (TempPass = "password") Then
                MsgBox "Please Change your Password", vbInformation, "New Password Required!"
                DoCmd.OpenForm "ChangesNewPassword", , , "[UserID]=" & ID
            Else
            If UserLevel = "Admin" Then
        'MsgBox "LoginID or Password Correct"
                DoCmd.OpenForm "Navigation Form"
                [COLOR="Yellow"]Forms![Navigation Form]![txtLogin] = TempLoginID[/COLOR]
                Forms![Navigation Form]![txtUser] = UserName
            Else
                DoCmd.OpenForm "frmlRequisitionOrder"
            End If
            End If
    End If
End If
End Sub
 
It appears the correct references look like:

Code:
Forms![Navigation Form]![NavigationSubform].[Form]![txtLogin] = TempLoginID
Forms![Navigation Form]![NavigationSubform].[Form]![txtUser] = UserName
 
It appears the correct references look like:

Code:
Forms![Navigation Form]![NavigationSubform].[Form]![txtLogin] = TempLoginID
Forms![Navigation Form]![NavigationSubform].[Form]![txtUser] = UserName

Genius, Thank you so much. Now it works.
 
Genius, Thank you so much. Now it works.


Actually not so much. I think you probably want to put the references back the way they were and move the textboxes to the main form (Navigation Form) so that the values will stick when you change tabs.


attachment.php
 

Attachments

  • Navform.jpg
    Navform.jpg
    88.5 KB · Views: 626
Actually not so much. I think you probably want to put the references back the way they were and move the textboxes to the main form (Navigation Form) so that the values will stick when you change tabs.


attachment.php

I just did, definitely better. thank you so much. :)
 

Users who are viewing this thread

Back
Top Bottom