I have a combobox called SelectDate on a form that dictates which date should be updated in a multi select listbox. I am using the select case to use the values in the combo box as you can see in the code below. This code works perfectly if I manually select the items in the list box but I want a select all button to process all items selected. I have code below for a select all button that will select all the items in the list box but my code to process the dates states that noting is selected. Is it my SelectAll button code or my DateProcessed code??? It worked fine before I used the Select Case method.
SelectAll button code:
Private Sub cmdSelectAll_Click()
If cmdSelectAll.Caption = "Select All" Then
Call ListBoxSelect(True)
cmdSelectAll.Caption = "UnSelect All"
Else
Call ListBoxSelect(False)
cmdSelectAll.Caption = "Select All"
End If
End Sub
Private Sub ListBoxSelect(boo As Boolean)
Dim intCounter As Integer
For intCounter = 0 To Me.EEList.ListCount - 1
Me.EEList.Selected(intCounter) = boo
Next intCounter
End Sub
DateProcess code that processes dates in listbox based on combobox selection.
Private Sub MarkAsSent_Click()
Dim db As DAO.Database
Dim var As Variant
Set db = CurrentDb
On Error GoTo Err_MarkAsSent_Click
If IsNull(Me.txtDateHolder) Then
MsgBox "No Date selected...", vbExclamation
End
End If
Select Case SelectDate.Value
Case "Date Sent to HR"
If IsNull(EEList.Column(0)) Then
MsgBox ("No record selected...")
End
End If
For Each var In Me.EEList.ItemsSelected
db.Execute ("UPDATE tblSeveranceData SET [Date Sent HR]=#" & Format(Me!txtDateHolder, "yyyy-mm-dd") & "# WHERE EID='" & Me.EEList.Column(0, var) & "'")
Next
Case "Date HR Verified"
If IsNull(EEList.Column(0)) Then
MsgBox ("No record selected...")
End
End If
For Each var In Me.EEList.ItemsSelected
db.Execute ("UPDATE tblSeveranceData SET [Date HR Verified]=#" & Format(Me!txtDateHolder, "yyyy-mm-dd") & "# WHERE EID='" & Me.EEList.Column(0, var) & "'")
Next
Case "Date Sent to Accounting"
If IsNull(EEList.Column(0)) Then
MsgBox ("No record selected...")
End
End If
For Each var In Me.EEList.ItemsSelected
db.Execute ("UPDATE tblSeveranceData SET [Date Sent ACCT]=#" & Format(Me!txtDateHolder, "yyyy-mm-dd") & "# WHERE EID='" & Me.EEList.Column(0, var) & "'")
Next
Case "Date Processed"
If IsNull(EEList.Column(0)) Then
MsgBox ("No record selected...")
End
End If
For Each var In Me.EEList.ItemsSelected
db.Execute ("UPDATE tblSeveranceData SET [Date Processed]=#" & Format(Me!txtDateHolder, "yyyy-mm-dd") & "# WHERE EID='" & Me.EEList.Column(0, var) & "'")
Next
Case "Date Letter was Signed"
If IsNull(EEList.Column(0)) Then
MsgBox ("No record selected...")
End
End If
For Each var In Me.EEList.ItemsSelected
db.Execute ("UPDATE tblSeveranceData SET [Date Letter Signed]=#" & Format(Me!txtDateHolder, "yyyy-mm-dd") & "# WHERE EID='" & Me.EEList.Column(0, var) & "'")
Next
Case "Date Sent for IC"
If IsNull(ICList.Column(0)) Then
MsgBox ("No record selected...")
End
End If
For Each var In Me.ICList.ItemsSelected
db.Execute ("UPDATE tblSeveranceData SET [Date Sent IC]=#" & Format(Me!txtDateHolder, "yyyy-mm-dd") & "# WHERE EID='" & Me.ICList.Column(0, var) & "'")
Next
Case Else
End Select
Call ListBoxSelect(False)
Call ListBoxSelect2(False)
cmdSelectAll.Caption = "Select All"
cmdSelectAll2.Caption = "Select All"
MsgBox "Dates updated successfully...", vbInformation
Me.EEList.Requery
Me.ICList.Requery
Forms!frmSeverance.Refresh
db.Close
Set db = Nothing
Exit_MarkAsSent_Click:
Exit Sub
Err_MarkAsSent_Click:
MsgBox Err.Description
Resume Exit_MarkAsSent_Click
End Sub
SelectAll button code:
Private Sub cmdSelectAll_Click()
If cmdSelectAll.Caption = "Select All" Then
Call ListBoxSelect(True)
cmdSelectAll.Caption = "UnSelect All"
Else
Call ListBoxSelect(False)
cmdSelectAll.Caption = "Select All"
End If
End Sub
Private Sub ListBoxSelect(boo As Boolean)
Dim intCounter As Integer
For intCounter = 0 To Me.EEList.ListCount - 1
Me.EEList.Selected(intCounter) = boo
Next intCounter
End Sub
DateProcess code that processes dates in listbox based on combobox selection.
Private Sub MarkAsSent_Click()
Dim db As DAO.Database
Dim var As Variant
Set db = CurrentDb
On Error GoTo Err_MarkAsSent_Click
If IsNull(Me.txtDateHolder) Then
MsgBox "No Date selected...", vbExclamation
End
End If
Select Case SelectDate.Value
Case "Date Sent to HR"
If IsNull(EEList.Column(0)) Then
MsgBox ("No record selected...")
End
End If
For Each var In Me.EEList.ItemsSelected
db.Execute ("UPDATE tblSeveranceData SET [Date Sent HR]=#" & Format(Me!txtDateHolder, "yyyy-mm-dd") & "# WHERE EID='" & Me.EEList.Column(0, var) & "'")
Next
Case "Date HR Verified"
If IsNull(EEList.Column(0)) Then
MsgBox ("No record selected...")
End
End If
For Each var In Me.EEList.ItemsSelected
db.Execute ("UPDATE tblSeveranceData SET [Date HR Verified]=#" & Format(Me!txtDateHolder, "yyyy-mm-dd") & "# WHERE EID='" & Me.EEList.Column(0, var) & "'")
Next
Case "Date Sent to Accounting"
If IsNull(EEList.Column(0)) Then
MsgBox ("No record selected...")
End
End If
For Each var In Me.EEList.ItemsSelected
db.Execute ("UPDATE tblSeveranceData SET [Date Sent ACCT]=#" & Format(Me!txtDateHolder, "yyyy-mm-dd") & "# WHERE EID='" & Me.EEList.Column(0, var) & "'")
Next
Case "Date Processed"
If IsNull(EEList.Column(0)) Then
MsgBox ("No record selected...")
End
End If
For Each var In Me.EEList.ItemsSelected
db.Execute ("UPDATE tblSeveranceData SET [Date Processed]=#" & Format(Me!txtDateHolder, "yyyy-mm-dd") & "# WHERE EID='" & Me.EEList.Column(0, var) & "'")
Next
Case "Date Letter was Signed"
If IsNull(EEList.Column(0)) Then
MsgBox ("No record selected...")
End
End If
For Each var In Me.EEList.ItemsSelected
db.Execute ("UPDATE tblSeveranceData SET [Date Letter Signed]=#" & Format(Me!txtDateHolder, "yyyy-mm-dd") & "# WHERE EID='" & Me.EEList.Column(0, var) & "'")
Next
Case "Date Sent for IC"
If IsNull(ICList.Column(0)) Then
MsgBox ("No record selected...")
End
End If
For Each var In Me.ICList.ItemsSelected
db.Execute ("UPDATE tblSeveranceData SET [Date Sent IC]=#" & Format(Me!txtDateHolder, "yyyy-mm-dd") & "# WHERE EID='" & Me.ICList.Column(0, var) & "'")
Next
Case Else
End Select
Call ListBoxSelect(False)
Call ListBoxSelect2(False)
cmdSelectAll.Caption = "Select All"
cmdSelectAll2.Caption = "Select All"
MsgBox "Dates updated successfully...", vbInformation
Me.EEList.Requery
Me.ICList.Requery
Forms!frmSeverance.Refresh
db.Close
Set db = Nothing
Exit_MarkAsSent_Click:
Exit Sub
Err_MarkAsSent_Click:
MsgBox Err.Description
Resume Exit_MarkAsSent_Click
End Sub