Hi June7,
I modified my code, added some IF statements after the loops, but they don`t work (pls see below). It says `compile error: wrong number of arguments or invalid property assignment.'
What I would like to reach: when the user doesn`t select any from a listbox, they would get a pop-up message ("Please select at least one.....!). Also, I would like to add a pop-up message saying `please clear all Employee selections` when they select any from the `Employee` listbox (because it is contradictory to select any as the user wants to see a List of Employees by certain criteria when clicking on the `Emp` button).
Code:
Private Sub cmdEmpl_Click()
Dim x As Long
' clear out old list selections
DoCmd.RunSQL ("Delete * from t_Employee")
DoCmd.RunSQL ("Delete * from t_Department")
DoCmd.RunSQL ("Delete * from t_State")
DoCmd.RunSQL ("Delete * from t_CourseQualification")
DoCmd.RunSQL ("Delete * from t_Skill")
'Add a for loop here for each list box
For x = 0 To Me.lstDepartment.ListCount - 1
If Me.lstDepartment.Selected(x) = True Then
DoCmd.RunSQL ("Insert into t_Department (Department) values ('" & _
Me.lstDepartment.ItemData(x) & "')")
End If
Next x
For x = 0 To Me.lstState.ListCount - 1
If Me.lstState.Selected(x) = True Then
DoCmd.RunSQL ("Insert into t_State (State) values ('" & _
Me.lstState.ItemData(x) & "')")
End If
Next x
For x = 0 To Me.lstCourseQualification.ListCount - 1
If Me.lstCourseQualification.Selected(x) = True Then
DoCmd.RunSQL ("Insert into t_CourseQualification (CourseQualification) values ('" & _
Me.lstCourseQualification.ItemData(x) & "')")
End If
Next x
For x = 0 To Me.lstSkill.ListCount - 1
If Me.lstSkill.Selected(x) = True Then
DoCmd.RunSQL ("Insert into t_Skill (Skill) values ('" & _
Me.lstSkill.ItemData(x) & "')")
End If
Next x
If (Count(t_Employee!Employee) <> 0) Then
Beep
MsgBox "Please clear all EMPLOYEE selections!", vbOKOnly, ""
End If
If (Count(t_Department!Department) = 0) Then
Beep
MsgBox "Please select at least one DEPARTMENT!", vbOKOnly, ""
End If
If (Count(t_CourseQualification!CourseQualification) = 0) Then
Beep
MsgBox "Please select at least one COURSE/QUALIFICATION!", vbOKOnly, ""
End If
If (Count(t_State!State) = 0) Then
Beep
MsgBox "Please select at least one STATE!", vbOKOnly, ""
End If
If (Count(t_Skill!Skill) = 0) Then
Beep
MsgBox "Please select at least one SKILL!", vbOKOnly, ""
End If
DoCmd.OpenReport "rptMain", acViewPreview, "", "", acNormal
cmdPrint_Click_Exit:
Exit Sub
cmdPrint_Click_Err:
MsgBox Error$
Resume cmdPrint_Click_Exit
End Sub