Solved

MS Access Need help with VBA where SQL statement

Posted on 2013-01-08
3
332 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query logic question 14 71
Outlook VBA question - How do I mark a message as read 2 60
Ms Access 2010 Setup (Executable file) 4 68
Outlook mail to Access 8 28
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

751 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