I am building a form in MS Access and I want some information to be pulled from one of several tables and populated into a text box, based on two drop downs that the user interacts with on the same form. After researching this, I found that DLOOKUP does what I am looking to do - the only problem is that I am having issues with getting it to work properly and I keep getting "#NAME" appearing in the text box.
I did some tutorials with DLOOKUP and had successful results but applying it to my projects has not been successful. In my project the FieldName of the Dlookup is static, which is "Description" but both the table name and Criteria are dynamic being passed to it as variables.
Currently I have four tables: tblAC, tblAT, tblAU, and tblCA - all following the design:
Table (Control_Number, Description)
Each table has four records, with the 'Control_Number" as the primary key. The control number is a string - because it can have letters in it.
What I have so far is:
Dim controlfamily1 As String
Dim control1 As String
controlfamily1 = "tbl" & CStr(Me.cboControlFamily.Value)
control1 = CStr(Me.cboControls.Value)
Me.txtDescription.ControlSource = DLookup("[Description]", controlfamily1, "[Control_Number] ='" & control1 & "'")
Where controlfamily1 is a variable of the type string - representing the TableName in the DlookUp. Control1 is a also a string variable representing the specific criteria to search on. I believe my issue all boils down to the my use of quotes, brackets and double quotes.
Thanks!