G
Guest
I posted a similar message in the Macro section and did not get a response,
possibly because a macro may not be the answer.
I have a form that allows the user to select criteria. From this criteria,
I need access to determine which report to run, and then run that report.
The criteria fields the user must enter are first name AND last name OR
category. From the information the user enters, the report will be either a
single label with the first name or last name, or a list of labels of every
name in the category.
Below is the code I have tried to work with, but it is not working.
Private Sub Print_Label_Click()
On Error GoTo err_Print_Label_click
Dim stDocName As String
Dim strcriteria As String
Dim strqueryname As String
Dim firstname, lastname, Category As String
'Checking for firstname
If (Form_criteria.firstname.Value <> "") Then
firstname = Form_criteria.firstname.Value
strcriteria = strcriteria & strqueryname & ".[firstname] = '" &
firstname & "'"
End If
'Checking for lastname
If (Form_criteria.lastname.Value <> "") Then
lastname = Form_criteria.lastname.Value
strcriteria = strcriteria & strqueryname & ".[lastname] = '" & lastname
& "'"
End If
'Checking for category
If (Form_criteria.Category.Value <> "") Then
Category = Form_criteria.Category.Value
'Add AND keyword if previous field value is not empty or else ignore the
AND
If (strcriteria <> "") Then
strcriteria = strcriteria & " AND "
End If
strcriteria = strcriteria & strqueryname & ".[category] = '" & Category
& "'"
End If
'checking for empty field values
If (Form_criteria.firstname.Value <> "") Then
stDocName = Form_criteria.firstname.Value
'build the query criteria base on field value
DoCmd.OpenReport stDocName, acPreview, , strcriteria
End If
exit_Print_Label_click:
Exit Sub
err_Print_Label_click:
MsgBox Err.Description
Resume exit_Print_Label_click
End Sub
Thanks for any help.
possibly because a macro may not be the answer.
I have a form that allows the user to select criteria. From this criteria,
I need access to determine which report to run, and then run that report.
The criteria fields the user must enter are first name AND last name OR
category. From the information the user enters, the report will be either a
single label with the first name or last name, or a list of labels of every
name in the category.
Below is the code I have tried to work with, but it is not working.
Private Sub Print_Label_Click()
On Error GoTo err_Print_Label_click
Dim stDocName As String
Dim strcriteria As String
Dim strqueryname As String
Dim firstname, lastname, Category As String
'Checking for firstname
If (Form_criteria.firstname.Value <> "") Then
firstname = Form_criteria.firstname.Value
strcriteria = strcriteria & strqueryname & ".[firstname] = '" &
firstname & "'"
End If
'Checking for lastname
If (Form_criteria.lastname.Value <> "") Then
lastname = Form_criteria.lastname.Value
strcriteria = strcriteria & strqueryname & ".[lastname] = '" & lastname
& "'"
End If
'Checking for category
If (Form_criteria.Category.Value <> "") Then
Category = Form_criteria.Category.Value
'Add AND keyword if previous field value is not empty or else ignore the
AND
If (strcriteria <> "") Then
strcriteria = strcriteria & " AND "
End If
strcriteria = strcriteria & strqueryname & ".[category] = '" & Category
& "'"
End If
'checking for empty field values
If (Form_criteria.firstname.Value <> "") Then
stDocName = Form_criteria.firstname.Value
'build the query criteria base on field value
DoCmd.OpenReport stDocName, acPreview, , strcriteria
End If
exit_Print_Label_click:
Exit Sub
err_Print_Label_click:
MsgBox Err.Description
Resume exit_Print_Label_click
End Sub
Thanks for any help.