0
votes

I am trying to update the text box using dlookup when the user selects a item in combo box, I cannot do dlookup in control source of text box since i need to store it in the table, so I am doing it in default value.

Here is the dlookup but it is not working:

=DLookUp([Ground Clearance_inches],"tbVehicles","[Vehicle]=[Forms]![Cover Data]![vehicle]")

note that Ground Clearance_inches is number datatype in the tbVehicles table.

2

2 Answers

1
votes

That should be

Private Sub vehicle_AfterUpdate() 
    ''Vehicle is a number
    Me.MyTextBoxNameHere = _
       DLookUp("[Ground Clearance_inches]","tbVehicles","[Vehicle]= " _
       & [Forms]![Cover Data]![vehicle]) 

    ''Vehicle is text 
    Me.MyTextBoxNameHere = _
       DLookUp("[Ground Clearance_inches]","tbVehicles","[Vehicle]= '" _
       & Replace([Forms]![Cover Data]![vehicle], "'","''") & "'") 

    ''If the current form is [Cover Data] then 
    Me.MyTextBoxNameHere = _
       DLookUp("[Ground Clearance_inches]","tbVehicles","[Vehicle]= '" _
       & Replace(Me.[vehicle], "'","''") & "'") 
End Sub
0
votes

I'm not sure about it being in the Default Value, but in VBA the where clause would be "[Vehicle]=" & [Forms]![Cover Data]![vehicle] Why not put it in the OnUpdate event of your combo box?