Solved DLookUp

E9-Tech

New member
Local time
Today, 08:41
Joined
Apr 28, 2021
Messages
4
I am trying to use the Lookup function to retrieve the description form the table tCodes and apply the description value in the description box in the form tDes with the After Update
1.png


2.png


For example if the users types any number between 100 and 199 in the Code field, the Description is populated with THALES as the number entered is between 100 and 199 and so on

I used the below code but I am not able to complete the VBA code

Code:
Private Sub Code_AfterUpdate()
    Description = DLookup("Description", "tCodes", "Code='" & CodeFrom & "'")
End Sub
 
1. Looks like CodeTo is a text field--is that true? If so you need to make it numeric.

Code:
"Code='" & CodeFrom & "'")"

2. In the above snippet, as it is typed, Code is referencing a field in tCodes. But no such field exists.

3. In the above snippet, as it is typed, CodeFrom is referencing a variable. You need it to reference a control on the form.

4. The above criteria only finds matches, it doesn't search ranges.

After you fix your table, this is the criteria of your Dlookup:

Code:
"CodeFrom<=" & Me!Code & " AND CodeTo>=" & Me!Code)
 
1. Looks like CodeTo is a text field--is that true? If so you need to make it numeric.

Code:
"Code='" & CodeFrom & "'")"

2. In the above snippet, as it is typed, Code is referencing a field in tCodes. But no such field exists.

3. In the above snippet, as it is typed, CodeFrom is referencing a variable. You need it to reference a control on the form.

4. The above criteria only finds matches, it doesn't search ranges.

After you fix your table, this is the criteria of your Dlookup:

Code:
"CodeFrom<=" & Me!Code & " AND CodeTo>=" & Me!Code)
Thanks for helping out with the code and spotting the error in the table!!
 

Users who are viewing this thread

Back
Top Bottom