Extra ) in query expression HELP

  • Thread starter Thread starter Warren
  • Start date Start date
W

Warren

I entered this code as directed and now I get the
following message:
RunTime Error '3075'
"Extra ) in Query Expression"

I CAN'T FIND IT IF IT IS THERE

CAN ANYONE HELP ME?
Private Sub cmdPreview_Click()

Dim strWhere As String
Dim lngLen As Long

'stDocName = "Recording Search Report2"
'DoCmd.OpenReport stDocName, acPreview
If Not IsNull(cboRecordingArtistName) Then
strWhere = strWhere & "([RecordingArtistName])
= """ & _
cboRecordingArtistName & """) AND "
End If
If Not IsNull(cboRecordingTitle) Then
strWhere = strWhere & "([RecordingTitle]) = """ & _
cboRecordingTitle & """) AND "
End If

If Not IsNull(cboTrackTitle) Then
strWhere = strWhere & "([TrackTitle]) = """ & _
cboTrackTitle & """) AND "
End If

If Not IsNull(cboTrackNumber) Then
strWhere = strWhere & "([TrackNumber]) = """ & _
cboTrackNumber & """) AND "
End If

If Not IsNull(cboTrackLength) Then
strWhere = strWhere & "([TrackLength]) = """ & _
cboTrackLength & """) AND "
End If

If Not IsNull(cboTrackTempo) Then
strWhere = strWhere & "([TrackTempo]) = """ & _
cboTrackTempo & """) AND "
End If

If Not IsNull(cboMusicCategory) Then
strWhere = strWhere & "([MusicCategory]) = """ & _
cboMusicCategory & """) AND "
End If

If Not IsNull(cboTrackSpecialty) Then
strWhere = strWhere & "([TrackSpecialty]) = """ & _
cboTrackSpecialty & """) "
End If

lngLen = Len(strWhere) - 8
If lngLen > 0 Then
strWhere = Left$(strWhere, lngLen)
End If

'open Report
DoCmd.OpenReport "Recording Search Report",
acViewPreview, , strWhere
End Sub
 
You either need to use two opening parentheses everywhere, or lose the one
after the field name:

If Not IsNull(cboRecordingArtistName) Then
strWhere = strWhere & "(([RecordingArtistName]) = """ & _
cboRecordingArtistName & """) AND "
End If

or

If Not IsNull(cboRecordingArtistName) Then
strWhere = strWhere & "([RecordingArtistName] = """ & _
cboRecordingArtistName & """) AND "
End If

I'd also revisit this part

lngLen = Len(strWhere) - 8
If lngLen > 0 Then
strWhere = Left$(strWhere, lngLen)
End If

If you're trying to remove the trailing AND, that's only 5 spaces (and
you're not adding it when cboTrackSpecialty isn't null, so you're actually
going to delete part of the string)

Try putting a Print.Debug strWhere directly before you open the report, just
so you can see whether it makes sense to you.
 
"Extra ) in Query Expression"

I CAN'T FIND IT IF IT IS THERE

The way I find those pesky unmatched parens is to read through the
string byte by byte, mentally adding 1 for each left paren and
subtracting 1 for each right. If I end up anywhere other than 0 I know
there's a mismatch; and if I get to the end of what should logically
be a nested parenthetical expression with a nonzero count, I know
where to "zero in" on the problem!
 
John Vinson said:
The way I find those pesky unmatched parens is to read through the
string byte by byte, mentally adding 1 for each left paren and
subtracting 1 for each right. If I end up anywhere other than 0 I know
there's a mismatch; and if I get to the end of what should logically
be a nested parenthetical expression with a nonzero count, I know
where to "zero in" on the problem!

That's exactly what *I* do. It's a handy technique.
 
Back
Top