在文本框中使用dlookup

时间:2012-03-06 18:22:09

标签: ms-access

我正在尝试使用dlookup更新文本框,当用户在组合框中选择一个项目时,我无法在文本框的控件源中执行dlookup,因为我需要将它存储在表中,所以我在默认情况下这样做值。

这是dlookup,但它不起作用:

  

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

请注意,Ground Clearance_inches是tbVehicles表中的数字数据类型。

2 个答案:

答案 0 :(得分:1)

那应该是

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

答案 1 :(得分:0)

我不确定它是否在默认值中,但在VBA中where子句将是“[Vehicle] =”& [表格]![封面数据]![车辆] 为什么不将它放在组合框的OnUpdate事件中?