The two "search" variables are dimentioned as Date - which means that when doing a
[tt]SearchD = Format(Text2.Text, "dd/mm/yyyy")
' or
SearchD = Format(Text2.Text, "yyyy-mm-dd")[/tt]
What you're actually doing, is formatting what might be a valid date to a string, which is then implicitly cast back to date again. I think, depending on locale, that might cause amusement;-), though since the latter version is unambiguous, SearchD should probably be assigned correct date.
DateSerial or CDate or something when assigning to Date variables?
Now - the second challenge here, is that there's no formatting of the date when concatenating them into the SQL string, which means that regardless of implicit casting/formatting etc when assigning to the date variable, the date that gets concatenated into the string, is according to locale, which seems UK here.
So - when doing this dynamic SQL stuff, the place to do the formatting is when concatenating into the sql string (or perhaps use string "search" variable, and format into those), not when assigning Date variables.
[tt]sqlInsurer = "SELECT * FROM Renewals_Extract WHERE PolicyEndDate BETWEEN #" & _
format$(SearchD, "yyyy-mm-dd") & "# AND #" & format$(searchE, "yyyy-mm-dd") & "#"[/tt]
Do try doing a
[tt]debug.print sqlInsurer[/tt]
then check it out (ctrl+g) both before and after these suggested alterations.
But - why not look into utilizing the parameters collection to avoid all this mess. Have a look at Chiph's faq faq709-1526, whith one approach ...
Roy-Vidar