missing syntax error (1 Viewer)

Rich M

Registered User.
Local time
Today, 05:05
Joined
Sep 22, 2018
Messages
12
I'm starting to learn VBA. Can someone please help with this.


If IsNull(Me.cboActors) Then
myActors = "[ActorsID] like '*'"
Else
myActors = "[ActorsID] = " & Me.cboActors
End If

It's telling me I have a missing operator '[ActorsID] = 14 andand'
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:05
Joined
Aug 30, 2003
Messages
36,131
Presumably there's more to the code, because that doesn't add the word "and" anywhere.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:05
Joined
Aug 30, 2003
Messages
36,131
Also, rather than use the Like bit when the control hasn't been filled out, simply omit it from the SQL/filter completely.
 

Rich M

Registered User.
Local time
Today, 05:05
Joined
Sep 22, 2018
Messages
12
sorry thought it was in that part of the function. here's the full function i'm working with

Dim myActors, myCategories, myGender, myYear As String
Dim task1, task2, strCriteria, strCriteria2 As String

If IsNull(Me.cboActors) Then
myActors = "[ActorsID] like '*'"
Else
myActors = "[ActorsID] = " & Me.cboActors
End If

'If IsNull(Me.cboCategories) Then
'myCategories = "[GenreID] like '*'"
'Else
'myCategories = "[GenreID] = " & Me.cboCategories
'End If

'If IsNull(Me.cboGender) Then
'myGender = "[Gender] like '*'"
'Else
'myGender = "[Gender] = '" & Me.cboGender & "'"
'End If

'If IsNull(Me.cboYearofrelease) Then
'myYear = "[YearofRelease] like '*'"
'Else
'myYear = "[YearofRelease] = " & Me.cboYearofrelease
'End If

strCriteria = myActors & "and" & myGender & "and" & myYearofrelease
strCriteria2 = myCategories
task1 = "Select * from qryMergeGenre where " & strCriteria
task2 = "Select * from qryMerge where " & strCriteria2
Me.subfrmSearch.Form.RecordSource = task1
Me.subfrmSearch.Form.RecordSource = task2
Me.subfrmSearch.Form.Requery

End Function
 

Rich M

Registered User.
Local time
Today, 05:05
Joined
Sep 22, 2018
Messages
12
was just working with the cboActors to see what syntax was missing
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 03:05
Joined
Aug 30, 2003
Messages
36,131
Well, this line is causing it:

strCriteria = myActors & "and" & myGender & "and" & myYearofrelease

because the other variables are empty. If you want to test with actors, just use:

strCriteria = myActors

then add the others. Make sure to include spaces around the "and":

strCriteria = myActors & " and " & myGender & " and " & myYearofrelease
 

Rich M

Registered User.
Local time
Today, 05:05
Joined
Sep 22, 2018
Messages
12
Thank you Pbaldy. like I said just starting to learn VBA. Do you know of any good sites for beginners to learn.
 

missinglinq

AWF VIP
Local time
Today, 06:05
Joined
Jun 20, 2003
Messages
6,423
Chrystal has an excellent “basics” tutorial:

Access Basics

This is a little more advanced, but still a great starting point, having 37 well written, well defined, clearly named chapters. Note that it says it's for v2016, but it started out being for v2007...and most of it, I believe, is still applicable to 2007 & 2010.

Microsoft Access Desktop Databases

MVP Allen Browne has an extensive list of tutorials and on-line reference materials:

Allen Browne's links to other Microsoft Access sites

Linq ;0)>
 

Users who are viewing this thread

Top Bottom