Variable Problem in VBA

suzeg

Registered User.
Local time
Today, 09:47
Joined
Jun 20, 2012
Messages
27
I cannot figure out why this is not working!
Any help appreciated.
Screen Shot of Code with error attached.

Variable_Problem_.png
 
Last edited by a moderator:
Re: Varibale Problem in VBA

wait so it's throwing an SQL syntax error when you are assigning a value to a string? That makes zero sense. Unless you are using that string name somewhere else as a public variable and its messing with some concurrently running code....maybe? I get mixed up with that stuff sometimes.

I just don't see how that would throw a (pretty specific) sql error. Do you recognize the query its describing?
 
Re: Varibale Problem in VBA

Next time, post the code here.
You waste my time to retype the code instead to use copy-paste.
StrWhere = "Job_ID = """ & Me.cboJobID & """ AND AMonth = """ & Me.cboMonths & """"
 
Last edited:
You're doing a comparison to a string literal that is not delimited as a string. The SQL parser can't find the field 'Task' and is trying subtract 004 from 'C,' which it also can't find. Contrast with . . .
Code:
. . . Job_ID = 'Task C-004' . . .
 
Re: Varibale Problem in VBA

Next time, post the code here.
You waste my time to retype the code instead to use copy-paste.
StrWhere = "Job_ID = """ & Me.cboJobID & """ AMonth = """ & Me.cboMonths & """"
Or if you don't want to type so many quotes:

StrWhere = "Job_ID = " & Chr(34) & Me.cboJobID & Chr(34) & " AND AMonth = " & Chr(34) & Me.cboMonths & Chr(34)

And Mihail - you missed the AND.
 
Indeed, Bob. With so many switches between Mozilla tabs... Thank you. I've edited my previous post.
 
Re: Varibale Problem in VBA

Or if you don't want to type so many quotes:

StrWhere = "Job_ID = " & Chr(34) & Me.cboJobID & Chr(34) & " AND AMonth = " & Chr(34) & Me.cboMonths & Chr(34)

And Mihail - you missed the AND.
I, personally, use the Chr(34) method because I find that it helps me keep straight what quotes are needed for the strings and which quotes are needed to be quotes. For me it is an easier thing visually to work out. For others perhaps that visual aspect isn't as important. Personal preference really.
 
Thank you all for the fix and the lively discussion. It worked - I think the Chr(34) will be very beneficial as I was getting lost in the quotes.
Again - much appreciated and I will copy and paste next time.
 

Users who are viewing this thread

Back
Top Bottom