strSQL

G

Guest

Hello,

I'm trying to build a query using strsql. The problem is in the where
clause. I have a field called identifiedstype and what I want is to add into
the where clause where identifiedstype = 'Person at scene' and [last name] =
somevalue. I'm prompted for an identifiedstype as if it's a parameter. My
code is below. Any assistance is greatly appreciated.


If Me.txtCrit1 > "" Then
If Me.txtOper1 = "like" Then
strSQL = "[" & Me.txtCrit1 & "]" & " " & (Me.txtOper1) & " '*" &
Trim(Me.txtVal1) & "*'" '
ElseIf Me.txtCrit1 = "Person At Scene Last Name" Then
strSQL = "[IdentifiedsType] = 'Person At Scene' And [last name] = " & "
'" & Trim(Me.txtVal1) & "'" '
ElseIf Me.txtCrit1 = "eventid" Or Me.txtCrit1 = "booknumber" Or
Me.txtCrit1 = "pagenumber" Or Me.txtCrit1 = "EVENTDATE" Or Me.txtCrit1 =
"ENTRYDATE" Then
strSQL = "[" & Me.txtCrit1 & "]" & " " & (Me.txtOper1) & "" &
(Me.txtVal1) & "" '
ElseIf Me.txtCrit1 > "" And Me.txtCrit1 <> "eventid" Or Me.txtCrit1 <>
"booknumber" Or Me.txtCrit1 <> "pagenumber" Or Me.txtCrit1 = "EVENTDATE" Or
Me.txtCrit1 = "ENTRYDATE" Then
strSQL = "[" & Me.txtCrit1 & "]" & " " & (Me.txtOper1) & "'" &
(Me.txtVal1) & "'" '
End If
End If
 
G

George Nicholson

Any assistance is greatly appreciated.

OK, lets have a fishing lesson. ("...teach a person how to fish...")

- Put a breakpoint on your last End If
- Run the code (form, etc.)
- When the breakpoint is reached, go to the VB editor
- Make sure the Immediate window is showing (View>Immediate)
- in the Immediate window, type: ? strSQL
- the result will be what you are telling Jet to do. Does it make sense?
right number of quotes, parentheses, etc.?
You should be able to take the resulting string, paste it into the query
designer's SQL view and have it run successfully.

I suspect your problems is in the number or placement of quotes.

HTH,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Another Filtering Question 3
Update if field not null 6
Slow Code/Query Execution 9
Wildcard question 1
"select case" 2
help with a VBA 4
Data Type Mismatch - String versus Long 3
Error 3075 Missing Operator 7

Top