Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dlookup help Please

Status
Not open for further replies.

newbee2

Technical User
Apr 21, 2002
85
I have seen many quetions put forward similar to mine, and from those and from The Microsoft Access Building Applications book V2.0 came up with the following which I can't get to work.
Private Sub Combo234_AfterUpdate()
'Update Freight Company controls based on value selected in Freight_ID combo box
Dim varFreightCompany, varPhone, varWebSite As Variant
varFreightCompany = DLookup("[FreightCompany]", "tblFreightCompany", "[FreightCompany] = " & FreightCompany)
varPhone = DLookup("[Phone]", "tblFreightCompany", "[Phone] = " & Phone)
varWebSite = DLookup("[WebSite]", "tblFreightCompany", "[WebSite] = " & WebSite)
If (Not IsNull(varFreightCompany)) Then Me![FreightCompany] = varFreightCompany
If (Not IsNull(varPhone)) Then Me![Phone] = varPhone
If (Not IsNull(varWebSite)) Then Me![WebSite] = varWebSite
End Sub
I ahve an unbound Combobox on my form which calls up an Id number from another table. When the Id number is selected I was hoping to auto fill 3 feilds on my form. Which it doesn't do. What am I doing wrong?
Thanks
Neewbee2
 
Try this for your dlookup:

varFreightCompany = DLookup("[FreightCompany]", "tblFreightCompany", "[FreightCompany] = '" & FreightCompany & "'")

You will notice the pair of ' around the field name you are using to compare with [FreightCompany].

This applies to all of your dlookups

hth

Jo
 
Thanx for the reply I did as you instructed but still cannot get the fields to update. I have tried a new tact which surprised me when it worked. Here it is.
Private Sub Combo234_AfterUpdate()
Dim strFilter As String
'Evaluate filter before it is passed to Dlookup function
strFilter = "Freight_ID=" & Me!Combo234.Column(0)
'Update Freight Company controls based on value selected in Freight_ID combo box
Me![FreightCompany] = DLookup("[FreightCompany]", "tblFreightCompany", strFilter)
Me![PHONE] = DLookup("[Phone]", "tblFreightCompany", strFilter)
Me![WebSite] = DLookup("[WebSite]", "tblFreightCompany", strFilter)

End Sub
It is a bit from the MS Northwind VBA for the sub form (a2k) and a lot of fingers crossed, and it worked.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top