Variable Problem in VBA (1 Viewer)

suzeg

Registered User.
Local time
Today, 14:29
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:

emorris1000

Registered User.
Local time
Today, 14:29
Joined
Feb 22, 2011
Messages
125
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?
 

Mihail

Registered User.
Local time
Tomorrow, 00:29
Joined
Jan 22, 2011
Messages
2,373
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:

MarkK

bit cruncher
Local time
Today, 14:29
Joined
Mar 17, 2004
Messages
8,180
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' . . .
 

boblarson

Smeghead
Local time
Today, 14:29
Joined
Jan 12, 2001
Messages
32,059
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.
 

Mihail

Registered User.
Local time
Tomorrow, 00:29
Joined
Jan 22, 2011
Messages
2,373
Indeed, Bob. With so many switches between Mozilla tabs... Thank you. I've edited my previous post.
 

boblarson

Smeghead
Local time
Today, 14:29
Joined
Jan 12, 2001
Messages
32,059
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.
 

suzeg

Registered User.
Local time
Today, 14:29
Joined
Jun 20, 2012
Messages
27
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

Top Bottom