-
[RESOLVED] SQL Dates
Hi,
I want to use a recordset to bring up all records which has a certain field with a date which is less than 5 days in advance. This includes dates in the past as well. Can anyone tell me how to do this using the .source property please? :)
If this is not possible I guess it won't be too hard to use VB functions to do it? i.e. If rsName.Fields("date field") <= Date+5 Then ...? :)
-
Re: SQL Dates
you should query the recordset when you open it, something like:
Code:
rs.Open "SELECT * FROM Table1 WHERE dDate <= #" & Format$(Date + 5, "mm/dd/yyyy") & "#", conn
-
Re: [RESOLVED] SQL Dates
Try something like this (not tested):
Code:
Option Explicit
Private Sub Form_Load()
Dim strSQL As String
Dim rs As New Recordset
strSQL = "SELECT DATE "
strSQL = strSQL & "FROM DATES "
strSQL = strSQL & "WHERE DATE<=TO_DATE('" & DateAdd("D", 5, Date) & "','DD.MM.YYYY')"
rs.Open strSQL, yourActiveConnection
If Not rs.EOF Then
Do Until rs.EOF
Debug.Print rs.Fields("DATE")
rs.MoveNext
Loop
End If
End Sub