Date Passing Problem

bidbud68

New member
Local time
Today, 18:47
Joined
Oct 17, 2012
Messages
3
Hi I have the following code where the strSQL Query selects records based on date, all works ie emails go off except the query doesnt select the records with the date = rdate. Please could you let me know the format of this line :
((Accounts.Date)=" & strCondition1 & ") . I have put strCondition into the query on which the report "Invoices For Month End Emailing" is based however it still returns all the records.

Code:
Option Compare Database
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Global Const JetDateTimeFmt = "\#dd\/mm\/yy hh\:nn\:ss\#;;;\N\u\l\l"

   Sub Send_Monthly_Invoices()
   
   Dim dbsReservations As DAO.Database
   Dim rstInvoices As DAO.Recordset
   Dim strSQL As String
   Dim rdate As Date
   Dim strCondition1 As String
   Dim strEmailRecipient As String
   
   'On Error GoTo ErrorHandler
   
   Set dbsReservations = CurrentDb
   
   rdate = InputBox("Enter Date")
   
   strCondition1 = "#" & rdate & "#"
   
   strSQL = "SELECT Reservations.ReservationID, Accounts.Item, Customers.EmailAddress, * FROM Customers INNER JOIN (Accounts INNER JOIN Reservations ON Accounts.ReservationID = Reservations.ReservationID) ON Customers.CompanyName = Reservations.Customer WHERE ((Accounts.Date)=" & strCondition1 & ") ORDER BY Accounts.Date;"
   Set rstInvoices = dbsReservations.OpenRecordset(strSQL, dbOpenDynaset)
   
   With rstInvoices
     Do Until .EOF
         DoCmd.OpenReport "Invoices For Month End Emailing", acViewNormal, , "Reservations.ReservationID=" & rstInvoices![Reservations.ReservationID]
         DoCmd.OpenReport "Booking Confirmation", acViewNormal, , "Reservations.ReservationID=" & rstInvoices![Reservations.ReservationID]
         Sleep (10000)
         Call SendInvoiceEmail(rstInvoices![EMAddress])
         .MoveNext
     Loop
   End With

   rstInvoices.Close
   dbsReservations.Close
   
   Set rstInvoices = Nothing
   Set dbsReservations = Nothing

   Exit Sub

   'ErrorHandler:
   '  MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description

   End Sub
 

Users who are viewing this thread

Back
Top Bottom