Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB Where Stmt

Status
Not open for further replies.

rbehnke

Technical User
Jul 20, 2007
20
US
I am using a text box on a form to complete the criteria(s) to filter a report. A WHERE stmt that works is:

strWhere = strWhere & " [GroupName] Like 'a*'"

The above example finds all Group names that start with the letter "a". GroupName is the field in the report (underlying query) and I'd like to have the field "txtGroupName" from the form supply the variable information. I can't seem to code what is needed in the WHERE stsmt in VB to get this done. The quotes, asterisk, etc. are making it a little difficult for me.

Can anyone help?

Thanks so much!
 
1. Wrong forum - you're asking about the VB code, not really a specific report question. For future Access VBA questions, Try over at forum705. And then try to think about where your question would get the best answer(s) for any others..

2. For now, your answer is: (without seeing all your other code... so it may be off somewhere else as well...


Code:
[GREEN]'Add this where you Dim your variables and such:[/GREEN]
Dim QU As String

[GREEN]'Then add this:[/GREEN]
QU = Chr(34) [GREEN]'This sets the variable equal to a double-quote - what Access Jet SQL uses, rather than the single quotes of MS ANSI SQL[/GREEN]

strWhere = strWhere & " [GroupName] Like " & QU & "a*" & QU

As I said, this may be a bit off, since we don't see all of your code. Try it out, and let us know..

--

"If to err is human, then I must be some kind of human!" -Me
 
Yes, that's exactly what I was looking for!!!!!

I was close, but it may have taken me quite a while to get it exactly correct.

Thanks so much!!!!!
 
Um, which one? [ponder]

--

"If to err is human, then I must be some kind of human!" -Me
 
I received this reply first and it worked fine.

strWhere = strWhere & " [GroupName] like '" & Me.txtGroupName & "*'"

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top