I realized that in my next step in identifying the exact records that are selected are also going to be grabbed to put into an email module. This will send each selected record that contains project information to each individual staff member. Counts won't be enough, so I had to try something else. In order to check my new code, I'm sending the information to a report. When the code is corrected, I'll send the information to an email module. I'm trying to identify each record that is selected by a checkbox. See code below and attached file. I think that I should use SQL to build selection criteria in the "WHERE" statement while looping through the checkboxes on the form, but again I need help.
Code:
=====================================
Public Function RunReport()
On Error GoTo ErrorHandler
Dim MyDB As Database
Dim ctl As Control, frm As Form
Dim qdf As QueryDef
Dim i As Integer, strSQL As String
Dim strWhere As String, strIN As String
Dim flgAll As Boolean
Dim strReport As String
Set frm = Forms!frmMainEntry.fctlNotifications.Form
Set MyDB = CurrentDb()
strReport = "rptDisplaySelection"
strSQL = "tsubProgramList.ProgramID, tsubProgramList.* "
For Each ctl In frm.Controls
With ctl
Select Case .ControlType
Case acCheckBox
If frm.Selected.Value = True = True Then
strIN = strSQL & "'" & tsubProgramList.ProgramID & "=" & frm.tsubProgramList.ProgramID.Value & "',"
Else
End If
End Select
End With
Next ctl
'create the WHERE string, stripping off the last comma of the IN string
strWhere = " WHERE [ProgramID] in (" & Left(strIN, Len(strIN) - 1) & ")"
'if "All" was selected, don't add the WHERE condition
If Not flgAll Then
strSQL = strSQL & strWhere
End If
MyDB.QueryDefs.Delete "qsubNotificationsProgram"
Set qdf = MyDB.CreateQueryDef("qsubNotificationsProgram", strSQL)
DoCmd.OpenReport strReport, acPreview
DoCmd.Maximize
DoCmd.RunCommand acCmdFitToWindow
'RESET QUERY ****************
'strSQL = "SELECT * FROM tsubProgramList "
'MyDB.QueryDefs.Delete "qsubNotificationsProgram"
'Set qdf = MyDB.CreateQueryDef("qsubNotificationsProgram", strSQL)
ExitProcedure:
On Error Resume Next
Set rstClone = Nothing
Exit Function
ErrorHandler:
MsgBox Err.Description
Resume ExitProcedure
End Function
=====================================
If the number of checkboxes selected in the table were the same number of checkboxes shown selected on the form, then this wouldn't be a problem. Take a look at the table after you put the date range on the form and you'll see what I mean. Ultimately, I need to use only those records that are nessary to give notification, rather than all the selected record shown in the table. I've tried switching recordsources instead of applying a filter and the results came out the same. There must be some other way.
Thanks,
PC