Date Expressions

  • Thread starter Thread starter Farman Khan via AccessMonster.com
  • Start date Start date
F

Farman Khan via AccessMonster.com

Hi.
two of my fields in the table are date type i.e. "from_date" and
"exp_date" i want to perform a date range test using another value from the
form to check if that new value lies between these two dates or not and
retrieve all the records from the table where it lies. I m using VBA.
 
you could make a query or report that shows the fields you want to display.
then you could put in a form two textboxes and a button.
under the button some vba-code that should be somethinglike this:

Private Sub [Your button]_Click()
Dim from_date, exp_date As Date
Dim strwhere As String
strwhere = "([date field in table you want to show] between format('" &
from_date & "',""dd-mm-yyyy"") and format('" & exp_date & "',""dd-mm-yyyy""))"
DoCmd.OpenReport "[your report name]", acViewPreview, , strwhere
End Sub
 
friend i want to check the FORM.FIELD in the TABLE.FIELD if it exists
BETWEEN the range of the TWO TABLE.FIELD

This is my code

SELECT * FROM rentals WHERE (#" & Me.txtfrom & "# >= from_date) AND (#" &
Me.txtfrom & "# < exp_return) AND (carreg='" & Me.txtcarreg & "')"

and it generates the following error

Run-time error '3075':
Syntax error in date in query expression'(#01.06.2006#>= fromdate) AND
(#01.06.2006#<exp_date) AND (carreg='2')'.

can anyone help ?
 
Back
Top