Solved Using DLookup to update text boxes - something wrong but can't spot the issue (1 Viewer)

Ryan142

Member
Local time
Today, 14:21
Joined
May 12, 2020
Messages
52
Hey guys,

I'm designing a user details form. It's going to have all of the data stored about the user.

I'm trying to load a form, and upon loading it will populate the text boxes with the already stored data. LoginID is the criteria I'm using here as it is unique to all users. Once the user logs in, it assigns a value to LoginID (which is a public variable). Then when they open the account details form it will use that LoginID to search against their stored data in tblUserDetails.

The issue I'm having is that no matter which user logs in, it will always only show one of the user's details everytime. I've made sure that LoginID is definitley changing each time by changing a label to the value.

Any help will be appreciated, here is the code:

Code:
Private Sub Form_Load()

    Me.lblComplete.Visible = False
    
    Me.lblInfo.Caption = LoginID

    Me.txtForename = DLookup("FirstName", "tblUserDetails", "LoginID = LoginID")
    Me.txtSurname = DLookup("LastName", "tblUserDetails", "LoginID = LoginID")
    Me.txtHouseNum = DLookup("HouseNumber", "tblUserDetails", "LoginID = LoginID")
    Me.txtStreet = DLookup("StreetName", "tblUserDetails", "LoginID = LoginID")
    Me.txtCity = DLookup("City", "tblUserDetails", "LoginID = LoginID")
    Me.txtPostCode = DLookup("PostCode", "tblUserDetails", "LoginID = LoginID")
    Me.txtMobileNum = DLookup("MobileNum", "tblUserDetails", "LoginID = LoginID")
    Me.txtEmail = DLookup("Email", "tblUserDetails", "LoginID = LoginID")
    Me.txtCardNum = DLookup("CardNum", "tblUserDetails", "LoginID = LoginID")
    Me.txtExpiry = DLookup("ExpiryDate", "tblUserDetails", "LoginID = LoginID")
    Me.txtSecurity = DLookup("SecurityCode", "tblUserDetails", "LoginID = LoginID")
    Me.txtRemarks = DLookup("Remarks", "tblUserDetails", "LoginID = LoginID")

End Sub
 

bob fitz

AWF VIP
Local time
Today, 14:21
Joined
May 23, 2011
Messages
4,717
Why not just bind the form and its controls to the table and let access do the work
 

Ryan142

Member
Local time
Today, 14:21
Joined
May 12, 2020
Messages
52
Why not just bind the form and its controls to the table and let access do the work

That's a thing I can do? Haha, I failed to mention I'm quite new to access and doing my first project (I've found myself posting here a few times already). Could you help me with the syntax for that and how I'd go about doing it? Thanks for the quick response
 

Minty

AWF VIP
Local time
Today, 14:21
Joined
Jul 26, 2013
Messages
10,355
Apart from the obvious answer Bob gave you, you aren't creating the criteria properly , you need to concatenate the value;

Me.txtForename = DLookup("FirstName", "tblUserDetails", "LoginID = " & LoginID)
 

Ryan142

Member
Local time
Today, 14:21
Joined
May 12, 2020
Messages
52
Apart from the obvious answer Bob gave you, you aren't creating the criteria properly , you need to concatenate the value;

Me.txtForename = DLookup("FirstName", "tblUserDetails", "LoginID = " & LoginID)

Ah that would be the reason thanks, as I said, quite new. But I'm curious as to how I would go about bob's answer as it sounds a lot more... efficient :D
 

bob fitz

AWF VIP
Local time
Today, 14:21
Joined
May 23, 2011
Messages
4,717
Ah that would be the reason thanks, as I said, quite new. But I'm curious as to how I would go about bob's answer as it sounds a lot more... efficient :D
Use the "Form Wizard" to get the basic bound form. Just a few mouse clicks :)
 

Users who are viewing this thread

Top Bottom