Array to field names in Query

pekajo

Registered User.
Local time
Tomorrow, 02:25
Joined
Jul 25, 2011
Messages
135
I loop thu a table to get field names

myArray(iCounter) = "[" & rstTableName.Fields("DJPR-Import") & "]"

into an array as I need them for a query ie

"SELECT DJPR1." & myArray(0) & ", DJPR1.[READY TIME],...

My issue is that if the field name is one word it works ok however when there are two words it comes thu as 'Expr1: DJPR1.[Ready date]' on the query and does not work.
ReadyDate works
Ready Date does not work.

Any ideas why?
Peter
 
where are you doing this?
can you show the Code.
it should work (on VBA).
 
Hi,

Just solved the issue.
Peter
 
In the absence of proper delimiters or bracketing, SQL sees a space in a field name but thinks it is like an expression with two variables that SHOULD - but does not - have some sort of operator between the variables.

Got to say that I don't think you properly copied your syntax for your loop.

Code:
myArray(iCounter) = "[" & rstTableName.Fields("DJPR-Import") & "]"

That syntax should be more like

Code:
myArray(iCounter) = "[" & rstTableName.Fields(iCounter) & "]"

The syntax YOU gave will either return a field name "DJPR-Import" or it will return nothing.
 
Just solved the issue.

For the benefit on others reading this and Without an explanation from you, I guess you added field delimiters to your array builder.
 

Users who are viewing this thread

Back
Top Bottom