ACC1x: Criteria Parameters Require Concatenated References (1.x)ID: Q95978
|
Moderate: Requires basic macro, coding, and interoperability skills.
Microsoft Access has both a SQL interpreter and an Access Basic
interpreter. Because some Access Basic commands and functions require SQL
syntax as a parameter, it may become confusing how the two work together.
For example, if you need to look up a description in a table called
Categories where [Category ID] is equal to whatever value is currently
in Forms!Form1!Field1, you cannot use the following code.
NOTE: In the following sample code, an underscore _ is used as a
line-continuation character. Remove the underscore from the end of the
line when re-creating this code.
DLookUp("Description", "Categories",_
"[Category ID] = Forms!Form1!Field1")
DLookUp("Description", "Categories",_
"[Category ID] = '" & Forms!Form1!Field1 & "'")
[Category ID] = 'BEVR'
When you make a function call such as
DLookUp("Description", "Categories", "[Category ID] = 'BEVR'")
SELECT Description FROM Categories WHERE [Category ID] = 'BEVR'
DLookUp("Description", "Categories",_
"[Category ID] = Forms!Form1!Field1")
[Category ID] = Forms!Form1!Field1
Dim D As Database, S As Snapshot
Set D = CurrentDB()
Set S = D.CreateSnapshot("Categories")
myvar = "BEVR"
S.FindFirst "[Category ID] = '" & myvar & "'"
Microsoft Access "User's Guide", Version 1.0, page 181 and Appendix C
Additional query words: concatenation
Keywords : kbprg
Version : 1.0 1.1
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: March 18, 1999