V
Vince Cole
I am receiving an error message: Syntax Error (missing operator) in Query
Expresison. Once again, I am able to print all reports from my database, but
I am trying to design a print button that will allow the user to print
selected report(s). Below is the code that I have for this print button:
Private Function BuildWhereCondition(strControl As String) As String
'Set up the WhereCondition Argument for the reports
Dim varItem As Variant
Dim strWhere As String
Dim ctl As Control
Set ctl = Me.Controls(strControl)
Select Case ctl.ItemsSelected.Count
Case 0 'Include All
strWhere = ""
Case 1 'Only One Selected
strWhere = "= '" & _
ctl.ItemData(ctl.ItemsSelected(0)) & "'"
Case Else 'Multiple Selection
strWhere = " IN ("
With ctl
For Each varItem In .ItemsSelected
strWhere = strWhere & "'" & .ItemData(varItem) & "', "
Next varItem
End With
strWhere = strWhere & Left(strWhere, Len(strWhere) - 2) & ")"
End Select
BuildWhereCondition = strWhere
End Function
Private Sub Command9_Click()
On Error GoTo Err_Command9_Click
Dim stDocName As String
strRptFilter = BuildWhereCondition("Stock List")
DoCmd.OpenReport "Keystone Stock Report", , , strRptFilter
Exit_Command9_Click:
Exit Sub
Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click
End Sub
Once again I am an Access and VB novice (actually, novice is too nice a word
for my experience level), so any help is greatly needed and would be greatly
appreciated.
Thanks - Vince
Expresison. Once again, I am able to print all reports from my database, but
I am trying to design a print button that will allow the user to print
selected report(s). Below is the code that I have for this print button:
Private Function BuildWhereCondition(strControl As String) As String
'Set up the WhereCondition Argument for the reports
Dim varItem As Variant
Dim strWhere As String
Dim ctl As Control
Set ctl = Me.Controls(strControl)
Select Case ctl.ItemsSelected.Count
Case 0 'Include All
strWhere = ""
Case 1 'Only One Selected
strWhere = "= '" & _
ctl.ItemData(ctl.ItemsSelected(0)) & "'"
Case Else 'Multiple Selection
strWhere = " IN ("
With ctl
For Each varItem In .ItemsSelected
strWhere = strWhere & "'" & .ItemData(varItem) & "', "
Next varItem
End With
strWhere = strWhere & Left(strWhere, Len(strWhere) - 2) & ")"
End Select
BuildWhereCondition = strWhere
End Function
Private Sub Command9_Click()
On Error GoTo Err_Command9_Click
Dim stDocName As String
strRptFilter = BuildWhereCondition("Stock List")
DoCmd.OpenReport "Keystone Stock Report", , , strRptFilter
Exit_Command9_Click:
Exit Sub
Err_Command9_Click:
MsgBox Err.Description
Resume Exit_Command9_Click
End Sub
Once again I am an Access and VB novice (actually, novice is too nice a word
for my experience level), so any help is greatly needed and would be greatly
appreciated.
Thanks - Vince