Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

MS Access Need help with VBA where SQL statement

How can I add "employee" (Me.cboEmp) to the delete statement?

I.E. I need to delete records by date & employee, in lieu of just dates because all users with the specified date will be deleted.


Private Sub Command103_Click()
Dim strSQL As String
Dim dtmNextDate As Date

If Me.cboEmp.ListIndex = -1 Then
    MsgBox " Please select employee"
    Me.cboEmp.SetFocus
    Exit Sub
End If

If Me.txtEnd & "" = "" Then
   MsgBox " Please select start date"
   Me.txtStart.SetFocus
   Exit Sub

End If

If Me.txtStart & "" = "" Then
   MsgBox " Please select end date"
   Me.txtEnd.SetFocus
   Exit Sub

End If

dtmNextDate = Me.txtStart
    Do Until dtmNextDate = Me.txtEnd + 1
    
        strSQL = "DELETE * FROM  tblEmpTimeOff WHERE etoDate BETWEEN #" & Me.txtStart & "# AND #" & Me.txtEnd & "#"
        CurrentDb.Execute strSQL, dbFailOnError
        dtmNextDate = dtmNextDate + 1
    Loop
    Me.cboEmp = ""
    Me.cboReason = ""
    Me.txtEnd = ""
    Me.txtStart = ""
    MsgBox "Records Deleted, Thank You"
End Sub

Open in new window

0
DJPr0
Asked:
DJPr0
1 Solution
 
mbizupCommented:
strSQL = "DELETE * FROM  tblEmpTimeOff WHERE (etoDate BETWEEN #" & Me.txtStart & "# AND #" & Me.txtEnd & "#) AND employee = " & chr(34) &  Me.cboEmp & chr(34)

Open in new window



Or if employee is a numeric ID:

strSQL = "DELETE * FROM  tblEmpTimeOff WHERE (etoDate BETWEEN #" & Me.txtStart & "# AND #" & Me.txtEnd & "#) AND employee = "   & Me.cboEmp

Open in new window

0
 
Arthur_WoodCommented:
What is the field that holds the employee identifier in tblEmpTimeOff?

AW
0
 
DJPr0Author Commented:
Thanks mbizup!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now