S
Slez via AccessMonster.com
I have a multi-select list box on a form which has 4 available reports which
open based on command buttons. The code for each of the command buttons
contains SQL which gets quite lengthy. I'm in the process of adding 2
additional report selections (for a total of 6) and would like to switch from
command buttons to an option group. I have done so successfully in the past
when a single record is selected from a combo box, but never with a multi-
select list box. I'm certainly no expert at VBA, and I'm trying to combine
code from both of the above applications to develop one that works. I'd like
to avoid all of the SQL and just feed off of the queries if that's possible.
So far...no luck.
My form, "frmEstimateSelector", has a multi-select list box called
"lstBidSelect", and an option group called "grpEstimReports", and 2 command
buttons, View and Print, for after selections are made.
I thought I'd try to prey on the vast knowledge offered in this forum. I
have done so often as of late and have really benefited a great deal! I have
posted my current code below with the hope that someone can steer me in the
right direction. Thank you in advance for any help with this matter!
Option Compare Database
Option Explicit ' Requires variables to be declared before they are used.
Sub PrintReports(PrintMode As Integer)
On Error GoTo Err_Preview_Click
' This procedure used in Preview_Click and Print_Click Sub procedures.
' Preview or print report selected in the ReportToPrint option group.
Dim varItem As Variant
Dim strBidSelected As String
For Each varItem In Me!lstBidSelect.ItemsSelected
strBidSelected = strBidSelected & ", " & Me.lstBidSelect.ItemData(varItem)
Next varItem
If Len(strBidSelected) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "No Selection!"
Exit Sub
End If
Select Case Me!grpEstimReports
Case 1
DoCmd.OpenReport "Proposal1", PrintMode
Case 2
DoCmd.OpenReport "rptEstimateDetail", PrintMode
Case 3
DoCmd.OpenReport "rptEstimateDetailInstall", PrintMode
Case 4
DoCmd.OpenReport "rptPrelimSummary", PrintMode
Case 5
DoCmd.OpenReport "rptMaterialSummary", PrintMode
Case 6
DoCmd.OpenReport "rptMaterialSummaryMisc", PrintMode
End Select
Exit_Preview_Click:
Exit Sub
Err_Preview_Click:
Resume Exit_Preview_Click
End Sub
Private Sub cmdPrintEstimInfo_Click()
PrintReports acNormal
End Sub
Private Sub cmdViewEstimInfo_Click()
PrintReports acPreview
End Sub
open based on command buttons. The code for each of the command buttons
contains SQL which gets quite lengthy. I'm in the process of adding 2
additional report selections (for a total of 6) and would like to switch from
command buttons to an option group. I have done so successfully in the past
when a single record is selected from a combo box, but never with a multi-
select list box. I'm certainly no expert at VBA, and I'm trying to combine
code from both of the above applications to develop one that works. I'd like
to avoid all of the SQL and just feed off of the queries if that's possible.
So far...no luck.
My form, "frmEstimateSelector", has a multi-select list box called
"lstBidSelect", and an option group called "grpEstimReports", and 2 command
buttons, View and Print, for after selections are made.
I thought I'd try to prey on the vast knowledge offered in this forum. I
have done so often as of late and have really benefited a great deal! I have
posted my current code below with the hope that someone can steer me in the
right direction. Thank you in advance for any help with this matter!
Option Compare Database
Option Explicit ' Requires variables to be declared before they are used.
Sub PrintReports(PrintMode As Integer)
On Error GoTo Err_Preview_Click
' This procedure used in Preview_Click and Print_Click Sub procedures.
' Preview or print report selected in the ReportToPrint option group.
Dim varItem As Variant
Dim strBidSelected As String
For Each varItem In Me!lstBidSelect.ItemsSelected
strBidSelected = strBidSelected & ", " & Me.lstBidSelect.ItemData(varItem)
Next varItem
If Len(strBidSelected) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "No Selection!"
Exit Sub
End If
Select Case Me!grpEstimReports
Case 1
DoCmd.OpenReport "Proposal1", PrintMode
Case 2
DoCmd.OpenReport "rptEstimateDetail", PrintMode
Case 3
DoCmd.OpenReport "rptEstimateDetailInstall", PrintMode
Case 4
DoCmd.OpenReport "rptPrelimSummary", PrintMode
Case 5
DoCmd.OpenReport "rptMaterialSummary", PrintMode
Case 6
DoCmd.OpenReport "rptMaterialSummaryMisc", PrintMode
End Select
Exit_Preview_Click:
Exit Sub
Err_Preview_Click:
Resume Exit_Preview_Click
End Sub
Private Sub cmdPrintEstimInfo_Click()
PrintReports acNormal
End Sub
Private Sub cmdViewEstimInfo_Click()
PrintReports acPreview
End Sub