Access 2016 VBA date range in a DLookUp

236 Views Asked by At

I have a user from called Main_View. I have 2 fields (QFrom and QTo) to supply a date range to search a table. I want records that have a date between the date range supplied.

QFROM = Textbox user puts the from date QTo = textbox user puts the to date

Table to look in is called ICRELQA which contains a column that holds the date it was entered (ICRELPASEQ - Data Type = short Date) and a field with text (ICRELPAA- Short Text). Using the below DLookUp I want to get the record that is between the date range.

My DLOOKUP IS:

A1_1 = DLookup("[ICRELPAA]", "ICRELQA", "[ICQAHREF] = 1 And [ICQAREF] = 1 And [ICRELQREL] = '" & Me.searchField & "' And [ICRELPASEQ] >= #" & DFROM & "# AND [ICRELPASEQ] <= #" & DTo & "#")

I have tried using Me.DFrom and ME.DTo in the DLookUp but had the same issue.

I have added the following code to make sure that the dates are in the correct format:

DFROM = Format(CDate(Me.QFrom), "dd/mm/yyyy")
    DTo = Format(CDate(Me.QTo), "dd/mm/yyyy")

When I press the button to trigger the DLookUp I get a result that is also outside of the date range entered.

How can I get the returned value to be JUST the record that is contained inside the date range?

0

There are 0 best solutions below