WHERE statement in VBA

  • Thread starter Thread starter m stroup
  • Start date Start date
M

m stroup

Dim Divis as string
Select Case optDivision.Value
Case 1
Divis = "Govt"
Case 2
Divis = LM
Case 3
Divis = "PW"
Case Else
MsgBox "Plese select a valid Division"
Exit Sub
End Select

sHaving = " WHERE qryBilletQuery.Status = 'Filled' AND qryBilletQuery.ITF <>
0 AND qryBilletQuery.Div = """ & Divis & """"

I changed DIVIS to be a variable and thought I had the right syntax in the
Where statement above. Please advise.
 
The syntax to the where statement appears to be correct, perhaps it's because
you forgot to enclose the LM in quotes under Case 2?

What error are you getting?

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
Thanks for that Jack. Regardless of the case that is selected, however, I
get a message box asking me to input Divis.
 
How about the Case Else statement... if the value of optDivision is not 1 2
or 3, there will be no value supplied to Divis (null), and this may prompt
such a message. Perhaps you can stop the function in that line (or redirect
to the exit procedure).

Can you verify that Divis is actually a value when it gets added to the SQL
string?

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
Wow... apparently the coffe I had this morning did me no good whatsoever...
you already have an exit sub in there.

I'm at a bit of a loss here... hopefully someone else can see something that
I'm not? (and we know now that I'm having trouble seeing things this
morning...)

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
Exactly what is contained in sHaving? (try putting Debug.Print sHaving
statement after you assign it a value and then look in the Immediate Window
to see what's there)

How are you using sHaving?
 
Thank you all. I am afraid I had a duh moment. My problem was configuration
control, having two forms, changing the code on one and using the other.

thanks for your forbearance!
 
Back
Top