Solved

MS Access Need help with VBA where SQL statement

Posted on 2013-01-08
3
329 Views
Last Modified: 2013-01-08
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
Comment
Question by:DJPr0
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 38755541
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
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 38755544
What is the field that holds the employee identifier in tblEmpTimeOff?

AW
0
 

Author Closing Comment

by:DJPr0
ID: 38755917
Thanks mbizup!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question