1

There is a table in MS Access having 3 columns:

  1. ID (Primary key)
  2. Date (Date/Time)
  3. Train no (short text)

I have designed a form where date can be selected from a combo box and according to the date selected, respective trains should be displayed.

Problem is, the query works fine on dates above 10 (like 11/1/2015) but below 10 (like 9/1/2015) it gives error : "No current record" . The record is there in the table but it doesn't display.

The query is : SELECT DISTINCT [Train No] FROM Issue WHERE [Date] = #" & dt & "#"

dt is the date selected from the combo box.

1 Answer 1

4

Try this:

Dim DateSelected As Date
Dim DateString   As String

DateSelected = DateValue(Me!YourComboBox.Value)
DateString = Format(DateSelected, "yyyy\/mm\/dd")

SELECT DISTINCT [Train No] FROM Issue WHERE [Date] = #" & DateString & "#"
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks :) It worked. Can u please explain why it takes only this format?
In SQL, string expressions for date values must be formatted as yyyy-mm-dd or mm-dd-yyyy (or slashes as separator). As yyyy-mm-dd also is the only reliable format for ADO, stick to the ISO format yyyy-mm-ss as a general rule.
But why then it was working for dates above 10 (like 11/1/2015) ? Does it parse differently for those formats?
I guess that if you Debug.Print your old SQL string, that would show why.
There is just a change of date format. Thanks for your time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.