M
Maresdd
I am trying to run the following code and keep getting a data type mismatch.
Can somebody please have a look and let me know where I'm going wrong.
Private Sub Command7_Click()
Dim ctl As Access.Control
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
Dim Val As Currency
Set db = CurrentDb()
Set qdf = db.QueryDefs("qry_payrolledit")
For Each varItem In Me!LstPayroll.ItemsSelected
strCriteria = strCriteria & "," & Me!LstPayroll.ItemData(varItem) & ""
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
strSQL = "DELETE tblpayroll.* " & vbCrLf & _
"FROM tblpayroll " & vbCrLf & _
"WHERE (((tblpayroll.Recnum) In (" & strCriteria & ")));"
DoCmd.OpenQuery "qry_payrolledit"
Set db = Nothing
Set qdf = Nothing
LstPayroll.RowSource = ""
DoCmd.SetWarnings True
Me.Employee.SetFocus
End Sub
Can somebody please have a look and let me know where I'm going wrong.
Private Sub Command7_Click()
Dim ctl As Access.Control
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
Dim Val As Currency
Set db = CurrentDb()
Set qdf = db.QueryDefs("qry_payrolledit")
For Each varItem In Me!LstPayroll.ItemsSelected
strCriteria = strCriteria & "," & Me!LstPayroll.ItemData(varItem) & ""
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
strSQL = "DELETE tblpayroll.* " & vbCrLf & _
"FROM tblpayroll " & vbCrLf & _
"WHERE (((tblpayroll.Recnum) In (" & strCriteria & ")));"
DoCmd.OpenQuery "qry_payrolledit"
Set db = Nothing
Set qdf = Nothing
LstPayroll.RowSource = ""
DoCmd.SetWarnings True
Me.Employee.SetFocus
End Sub