0

I'm self studying a VBA code, I got one question. Hope can get your help.

Here is my situation:

I've 15 records in the table, they're date value like:
31 Jan 2016, 29 Feb 2016, 30 Nov 2016, 31 Dec 2016
the field name is [dayTo]

And I've two Forms,
1st Form = "F_temp", a txt box "date0" in this form.
2nd Form = "F_visitorRec", this form will show the record from [dayTo]

I'd like to made a openForm with condition like:

DoCmd.OpenForm "F_visitorRec", acNormal, , "[dayTo] >= #" & Me![date0] & "#"

But I never success, if I input 01 Nov 2016, it will show all 15 record.
If I input 09 Nov 2016, it will show the date large than September.
If I input 13 Nov 2016, the result is correct,
it can show the record lager than 13 Nov 2016.
I know this problem should related to the date format, but I try many method but still can't fix.

Hope can get your help.

2
  • What is the data type of your table date? It is always best to refer to dates as year-month-day. Commented Nov 21, 2016 at 16:33
  • Thanks ! I've set the field, txt box, query format to yyyy/mmm/dd. But still not work. Gustav's ans is work. Many thanks ! Commented Nov 22, 2016 at 3:05

1 Answer 1

1

Apply a proper format to the string expression for the date value:

DoCmd.OpenForm "F_visitorRec", acNormal, , "[dayTo] >= #" & Format(Me![date0].Value, "yyyy\/mm\/dd") & "#"
Sign up to request clarification or add additional context in comments.

3 Comments

Many Thanks ! Gustav ! <br/> But which format I should choose in the field, txt box, query ? or just leave it blank ?
I've try following but why didn't work. <br/> Dim date0 As String date0 = Format(Date, "dd\mmmm\yyyy")
Typically, you set the Format property to Short Date or Long Date.

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.