Compile error: method or data member not found!

Abouya

Registered User.
Local time
Today, 01:42
Joined
Oct 11, 2016
Messages
88
I Created a table called tblTracking to track log ins and outs based on users login. then i created two queries, one is Append [QryLogInTime] and the other Update [QryLogOutTime]. I get Compile error: method or data member not found! after I login to the main form.

I have this code in Load event on the main form:

Code:
Private Sub Form_Load()
Dim User As String
Me.txtUser = Me.txtUserName
Me.txtLogin = DLookup("UserName", "tblUser", "UserLogin ='" & User & "'")

Dim strDocName As String

strDocName "QryLogInTime"
DoCmd.OpenQuery strDocName, acViewNormal, acEdit
End Sub

Can someone please help me find the issue? Thank you.
 
On what line? You realize you never set the User variable to anything? Did you mean to set that instead of a form control?
 
On what line? You realize you never set the User variable to anything? Did you mean to set that instead of a form control?

I corrected the code , now i get same error after i login to navigation form:

Code:
Private Sub Form_Load()
Dim User As String
User = Environ("Username")

Me.txtLogin = DLookup("UserName", "tblUser", "UserLogin ='" & User & "'")

Dim strDocName As String
strDocName = "QryLogInTime"
[B]DoCmd.OpenQuery strDocName, acViewNormal, acEdit[/B]

End Sub
 
On what line? Have you double checked the control names?
 
On what line? Have you double checked the control names?

The one in bold. this one: DoCmd.OpenQuery strDocName, acViewNormal, acEdit.

I get this error: runtime error 3085: Undefined function 'getUserLogin' in expression.
 
Sounds like you've tried to use a function in the query that doesn't exist or isn't public.
 
Sounds like you've tried to use a function in the query that doesn't exist or isn't public.

exactly, I'm following a video tutorial i found in Youtube. here is a screenshot:

is there any solution? thank you.

and here is my code for Login form click event that works good:

Option Compare Database



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"
                Forms![Navigation Form]![txtLogin] = TempLoginID
                Forms![Navigation Form]![txtUser] = UserName
            Else
                DoCmd.OpenForm "Navigation Form"
                Forms![Navigation Form]![txtLogin] = TempLoginID
                Forms![Navigation Form]!NavigationButton99.Enabled = False
                Forms![Navigation Form]!NavigationButton69.Enabled = False
                Forms![Navigation Form]!NavigationButton17.Enabled = False
                Forms![Navigation Form]!NavigationButton19.Enabled = False
                Forms![Navigation Form]!NavigationButton75.Enabled = False
                Forms![Navigation Form]![txtUser] = UserName
            End If
            End If
    End If
End If
End Sub
 

Attachments

  • qryLoginTime.jpg
    qryLoginTime.jpg
    94.8 KB · Views: 171
That query calls a function; you'd have to have that function in a standard module. Presumably the video pointed you to it.
 
it does work, i had to fill in the first row on the table and then i tried to login and it saved login time.

Is there a way to change this :

Code:
Dim User As String
User = Environ("Username")

for the actual person who logged in in Login form.

in the video review it mentions this, but i have no idea how to change it.

"you can change from Me.user = Environ("Username")
to Me. user = Me.txtuserName if you do not close form after click OK button,
instead make Log in form invisible by using Me.visible = false. Use this code
under On Load event of Log in Form."
 
Last edited:
The thing about Environ("Username") is that it SHOULD return the name of the user who logged in no matter when or from where it is called, provided you were in a domain-based environment or if your single workstation had decent user login setup. You should be able to find a Public location for storing that name (I recommend a general module dedicated to your user security functions) but there is nothing wrong with calling your function more than once.

The discussion you referenced in that video review (post #9) seems incorrect or incomplete somehow... If you are using "Me.user" or "Me.txtuserName" in reference to a person who logged in using some type of login form, then it implies that the variables are PUBLIC and also that they are persistent (meaning that the login form doesn't close.) But it seems somehow redundant since Me can only refer to one form at a time (by context) and so having Me.User set equal to Me.txtUserName might do nothing useful. Let me explain.

If this is any version of Access after 2003, there is no inherent user security in a form, so there is no need (or inherent place) to remember a user or to identify a user for the purpose of security arbitrary within an Access structure. Therefore Me.User and Me.txtUserName have to BOTH be variables in order to exist. I looked at form properties using Object Browser and couldn't find a property named ".User" so that is why I am making that statement. Therefore, Me.User implies that in the declaration area of the Class module, you have a Public User as String declaration. I might imagine Me.txtUserName is actually a reference to a control named [txtUserName].

Therefore I see no point in setting one public variable equal to another public variable. Now if you intended to pick up the user's login name from the LOGIN form, any reference based on "Me.x" would be the inappropriate place to store it for use by another form because either the login form or the other form could not be referenced by "Me.x" in a single expression. "Me" as a shortcut is damned useful - but not sentient.
 

Users who are viewing this thread

Back
Top Bottom