Hi, I would be grateful for some fresh eyes on this if possible.
I have a report form that runs a series of reports, for each report I have 2 buttons, one to run all the sponsors 'Run All' and another 'Run Selection' that runs all sponsors selected from a combo box. These boxes work with no problems. However I have had to set a third box that resets the combo box after the selection button has been used and before the ‘select all’ button can be used, as the table needs to be repopulated.
What I am trying to do is combine everything into one button but cannot seem to collate the codes correctly.
I have been trying to link them with an if /else statement but cannot get it to work. Each button code is as follows:
Refresh Button
[Private Sub Command25_Click()
Me.Sponsor_List = -2
Me.Command25.SetFocus
Dim x As Long
'
' clear out old selected states list
'
DoCmd.SetWarnings (WarningsOff)
DoCmd.RunSQL ("Delete * from [Apps Partners T]")
For x = 0 To Me.Sponsor_List.ListCount - 2
If Me.Sponsor_List.Selected(x) = False Then
DoCmd.RunSQL ("Insert into [Apps Partners T] (sponsor) values ('" & _
Me.Sponsor_List.ItemData(x) & "')")
DoCmd.SetWarnings (WarningsOn)
End If
Next x
End Sub]
Run all – Basic embedded macro to open report
Run selection
[Private Sub Command14_Click()
Dim x As Long
'
' clear out old selected states list
'
DoCmd.SetWarnings (WarningsOff)
DoCmd.RunSQL ("Delete * from [Apps Partners T]")
For x = 0 To Me.Sponsor_List.ListCount - 2
If Me.Sponsor_List.Selected(x) = True Then
DoCmd.RunSQL ("Insert into [Apps Partners T] (sponsor) values ('" & _
Me.Sponsor_List.ItemData(x) & "')")
End If
DoCmd.SetWarnings (WarningsOn)
Next x
'
' open query
'
Const REPORTCANCELLED = 2501
On Error Resume Next
DoCmd.RunMacro "AppsPostInSummary"
DoCmd.OpenReport "CIN Report Apps", View:=acViewPreview
Select Case Err.Number
Case 0
' no error
Case REPORTCANCELLED
' anticipated error, so ignore
Case Else
' unknown error, so inform user
MsgBox Err.Description, vbExclamation, "Error"
End Select
End Sub]
Your thoughts would be appreciated.