The reason for the ampersands is because you are inserting a dynamic value into a static string. Let me explain:
I want to build a select string, based on a date field on my form. If I built the string like this:
"SELECT * FROM Orders WHERE OrderDate = Me.OrderDate"
It would return this:
SELECT * FROM Orders WHERE OrderDate = Me.OrderDate
This select statement will not work in that the parser will be looking for a VALUE in the WHERE clause, NOT the string "Me.OrderDate"
If I write it like this
"SELECT * FROM Orders WHERE OrderID = #" & Me.OrderDate & "#"
I have in essence created two strings with a value inserted in between them. My first string is this:
"SELECT * FROM Orders WHERE OrderID = #"
My value from my form may be 06/01/2002
And my last string is this:
"#"
The string will first create this:
SELECT * FROM Orders WHERE OrderID = #
Then it will add the value of the Order date on my form (Me.OrderDate):
SELECT * FROM Orders WHERE OrderID = #06/01/2002
Then it will add the last pound sign (#):
SELECT * FROM Orders WHERE OrderID = #06/01/2002#
You are simply inserting a dynamic value into that string using the ampersands (concatenation).
Just remember that if the part of the select statement is a dynamic value, it must be surrounded by ampersands. Any symbols (', #, etc) must be included as part of the string before and after the dynamic value. ONLY the value itself is between the ampersands.
Hopefully this will help. Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?