How to run more than one report

S

Sky Warren

I have a form that allows a user to click a check box next to each record
they want to appear in preview window, afterwards they click a button that
runs my "Labels" report. I would like to be able to send the selected records
output to my other reports like "Mailing List", etc.

Is there a way to change the code that will allow different reports to run
using the same output. Below is the code from my form:


Dim colCheckBox As New Collection

Public Function IsChecked(vID As Variant) As Boolean
Dim lngID As Long
IsChecked = False
On Error GoTo exit1
lngID = colCheckBox(CStr(vID))
If lngID <> 0 Then
IsChecked = True
End If
exit1:
End Function

Private Sub Command13_Click()
Debug.Print "contact = " & Me.ContactID
If IsChecked(Me.ContactID) = False Then
colCheckBox.Add CLng(Me.ContactID), CStr(Me.ContactID)
Else
colCheckBox.Remove (CStr(Me.ContactID))
End If
Me.Check11.Requery
End Sub

Private Function MySelected() As String
Dim i As Integer
For i = 1 To colCheckBox.Count
If MySelected <> "" Then
MySelected = MySelected & ","
End If
MySelected = MySelected & colCheckBox(i)
Next i
End Function

Private Sub Command16_Click()
Dim strWhere As String
strWhere = MySelected
If strWhere <> "" Then
strWhere = "ContactID in (" & strWhere & ")"
End If

DoCmd.OpenReport "Grace's Clients", acViewPreview, , strWhere
End Sub
 
J

John Vinson

I have a form that allows a user to click a check box next to each record
they want to appear in preview window, afterwards they click a button that
runs my "Labels" report. I would like to be able to send the selected records
output to my other reports like "Mailing List", etc.

For heaven's sake, rename your command buttons! I can't figure out
what Command15 is supposed to do, and in two months you won't be able
to either! <g>

You'll need to change the Sub names but it'll be worth the effort.

You can open any report you wish. You might want to have a listbox or
combo box with the names of the reports; rather than

DoCmd.OpenReport "Grace's Clients", acViewPreview, , strWhere

you could use code like

Dim strReportName As String
strReportName = Me!cboChooseReport
DoCmd.OpenRepoft strReportName, acViewPreview, , strWhere

John W. Vinson[MVP]
 
S

slobbering_dog

Sky Warren said:
I have a form that allows a user to click a check box next to each record
they want to appear in preview window, afterwards they click a button that
runs my "Labels" report. I would like to be able to send the selected
records
output to my other reports like "Mailing List", etc.

Is there a way to change the code that will allow different reports to run
using the same output. Below is the code from my form:


Dim colCheckBox As New Collection

Public Function IsChecked(vID As Variant) As Boolean
Dim lngID As Long
IsChecked = False
On Error GoTo exit1
lngID = colCheckBox(CStr(vID))
If lngID <> 0 Then
IsChecked = True
End If
exit1:
End Function

Private Sub Command13_Click()
Debug.Print "contact = " & Me.ContactID
If IsChecked(Me.ContactID) = False Then
colCheckBox.Add CLng(Me.ContactID), CStr(Me.ContactID)
Else
colCheckBox.Remove (CStr(Me.ContactID))
End If
Me.Check11.Requery
End Sub

Private Function MySelected() As String
Dim i As Integer
For i = 1 To colCheckBox.Count
If MySelected <> "" Then
MySelected = MySelected & ","
End If
MySelected = MySelected & colCheckBox(i)
Next i
End Function

Private Sub Command16_Click()
Dim strWhere As String
strWhere = MySelected
If strWhere <> "" Then
strWhere = "ContactID in (" & strWhere & ")"
End If

DoCmd.OpenReport "Grace's Clients", acViewPreview, , strWhere
Just add the same "DoCmd" line in here with the report you want to run,
if the underlying query can use the same checked records for its data /
filtering.

Cheers,


Craig Smith
 
S

Sky Warren

Hi John,

Thanks for your input. I tried your code and it worked great. Sorry about
the messy coding too, my bad dude. I renamed those Subs and gave them
meaningful descriptions as you suggested.

Sorry for taking so long to answer back and give you mega props.

-Sky
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top