Sub/Function not defined (1 Viewer)

arage

Registered User.
Local time
Today, 10:58
Joined
Dec 30, 2000
Messages
537
Sub/Function not defined
I’m trying to user the enclosed function to build my report’s filter criteria but as per below, the COMMANDBARCOMBOBOX statement keeps stopping with the error message that the “Sub or Function is not defined.” Any help would be appreciated.

'determines WHERE criteria to apply to a report…

Function buildSQL()

strSQL = "PromotionType= " & Choose(CommandBarComboBox(filterType).ListIndex, "BE", "OA") & " and year(mediaStartDate) like filteryear"

DoCmd.OpenReport objName, acViewPreview, , strSQL

End Function
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:58
Joined
Feb 19, 2002
Messages
43,346
strSQL = "PromotionType= " & Choose(CommandBarComboBox(filterType).ListIndex, "BE", "OA") & " and year(mediaStartDate) = " & filteryear & ";"

filteryear was being interpreted as a function. Since it is not defined in the function that you posted, you're still going to have trouble with the statement. Should you be referring to a form field - Forms!YourForm!YourFilterYear ?

I also changed LIKE to =. Never use LIKE unless you are supplying partial values and in that case, you need to surround it with asterisks as in - Like '*" & filteryear & "*';"
 

arage

Registered User.
Local time
Today, 10:58
Joined
Dec 30, 2000
Messages
537
Well, placing your code doesn’t stop the error unfortunately. You didn’t address the CommandBarComboBox issue I stated above, is that ok by you? Because access doesn’t think so. :D
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 05:58
Joined
Feb 19, 2002
Messages
43,346
I told you that what I suggested would probably not work because filteryear is not defined in the function! Where is it comming from?
 

Users who are viewing this thread

Top Bottom