Results 1 to 6 of 6
  1. #1
    Oneclo1 is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2024
    Posts
    6

    Angry VBA in Access

    Hello,

    Im building a login form for an Access Data base, i keep getting the error "compile Error: Method or data member not found" when i try to test the form. when i debug it highlights the the folowing text in the code: .Value/

    The code i have it VBA is:

    Private Sub LogOnBtn_Click()
    Dim ID As Long, PW As String
    ID = Nz(DLookup("UserID", "USerIDT", "UserName=""" & UserName & """"), 0)
    If ID = 0 Then
    MsgBox "User not found"
    Quit




    End If


    PW = Nz(DLookup("Password", "UserIDT UserID=" & ID), "")
    If PW <> Password Then
    Quit


    End If


    TempVars("username") = UserName.Value <--------This is what is highlighted with the error.


    End Sub

    Click image for larger version. 

Name:	VBA.PNG 
Views:	19 
Size:	22.8 KB 
ID:	51865Click image for larger version. 

Name:	VBA.PNG 
Views:	19 
Size:	15.5 KB 
ID:	51864

    Thank you in advance
    Last edited by Oneclo1; 06-19-2024 at 06:03 PM. Reason: Add Photos

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,941
    what is UserName? a control on a form? a field in a table? a global variable?

    So far as I can see it has not been defined - use of .value implies a form control

    And you should have Option Explicit at the top of every module, just below Option Compare Database so compile errors are picked up when you compile your code and not when you run it.

    you also have a problem with this line

    PW = Nz(DLookup("Password", "UserIDT UserID=" & ID), "")

    should be

    PW = Nz(DLookup("Password", "UserIDT", "UserID=" & ID), "")

  3. #3
    Oneclo1 is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2024
    Posts
    6
    UserName is a field in a table sane one as in the first line.
    I thought i had it defined, building this form is new to me.
    I had Option Explicit on top, i removed it to see if that would fix the issue. i forgot to put it back.
    I fix that like, i modified that as well trying to figure out the problem.

  4. #4
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Do you have a textbox on the form where the user is supposed to type in the UserName?
    Access will give that textbox a default name of textnnn or the like. You want to rename the textbox to something like txtUserName. (Other tab on property sheet)
    Then use txtUserName in your code:

    ID = NZ(DLookup("UserID","UserIDT","UserName='" & txtUserName & '") ,0)

    then

    Tempvars!username=Me.txtUserName.Value

  5. #5
    Oneclo1 is offline Novice
    Windows 10 Office 365
    Join Date
    Jun 2024
    Posts
    6
    Thanks for the reply, i actually figured this one out, the names were wrong in the properties. but now i get the error: runtime error '438': Object doesnt support the property or method and highlights
    If PW <> Password Then.
    What could cause this error?

  6. #6
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,742
    Quote Originally Posted by Oneclo1 View Post
    Thanks for the reply, i actually figured this one out, the names were wrong in the properties. but now i get the error: runtime error '438': Object doesnt support the property or method and highlights
    If PW <> Password Then.
    What could cause this error?
    Same deal as txtUserName. Rename the textbox that the user types the password into.

    If PW <> Me.txtPassword Then

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums