Peter Molnar
Peter Molnar

Reputation: 111

Date from TextBox to SQL in MS Access Form

In my country we use the format 2020. 09. 31. When I try to use it to build SQL query it dosn't works.

    IncomingInvoiceList.RowSource = "SELECT InvoiceDate, DistributorName FROM IncomingInvoice WHERE InvoiceDate BETWEEN #2020/04/31# AND " & TextBox & ")" 

The static #2020/04/31# format is ok, but the TextBox data (short format in our country) not. How to cast it?

Upvotes: 1

Views: 337

Answers (1)

Gustav
Gustav

Reputation: 55806

Format your textbox value as a string expression for the date - and don't include an invalid day of April:

IncomingInvoiceList.RowSource = "SELECT InvoiceDate, DistributorName FROM IncomingInvoice WHERE InvoiceDate BETWEEN #2020/04/30# AND #" & Format(TextBox, "yyyy\/mm\/dd") & "#)" 

Upvotes: 1

Related Questions