Syntax for selection criteria used by a query (1 Viewer)

Lanason

Registered User.
Local time
Today, 00:49
Joined
Sep 12, 2003
Messages
258
Morning guys

I have a routine that sends scheduled emails.
It runs down a list of records (Myrec1) and runs those that need to be run. A parameter is set for selection criteria in a query.

Some emails then have a sub routine loop (Myrec2) that then sends personalised emails to selected people rather than a generic email.

I have two issues
1) Testing the sub loop using a fixed field name (Owner) to send to owners but I cannot get the right syntax for the quotation marks "
GBL_stLinkCriteria = "'Owner = '" & myrec2![Owner] & "''"
:confused: Can anyone help with the syntax?:banghead:

Secondly:
2) I want to pick up the name of the field as a variable from the sub routine data (myrec2) so that the Owner (above) field can be a variable - something like . . . .
GBL_stLinkCriteria - "'" & myrec1![stLinkCriteria] & " = '[" & myrec2![VariableName] & "]'"
:confused: Again can anyone help with the syntax?:banghead:
 

June7

AWF VIP
Local time
Yesterday, 15:49
Joined
Mar 9, 2014
Messages
5,465
Exactly how are you using GBL_stLinkCriteria? Post procedure.
 
Last edited:

Lanason

Registered User.
Local time
Today, 00:49
Joined
Sep 12, 2003
Messages
258
I am calling a module with this code in it

DoCmd.OpenReport GBL_StDocName, acViewReport, , GBL_stLinkCriteria, acNormal

DoCmd.SendObject acReport, GBL_StDocName, acFormatPDF, GBL_MailTo, GBL_MailCC, GBL_MailBcc, GBL_Subject, GBL_MailGreeting & GBL_MailMessage & GBL_MailSignature, True
 

June7

AWF VIP
Local time
Yesterday, 15:49
Joined
Mar 9, 2014
Messages
5,465
Correct syntax:

GBL_stLinkCriteria = "[Owner] = '" & myrec2![Owner] & "'"

or:
GBL_stLinkCriteria = "Owner = '" & myrec2("Owner") & "'"

Field name goes on left and filter parameter on the right.

Brackets [] define object names and are needed if names have spaces or special characters or are reserved words. Apostrophes delimit parameters if field is text type.

As for part 2, not sure what goal is. Why would field name need to be variable? How is stLinkCriteria set?
 

Users who are viewing this thread

Top Bottom