dlookup between dates

Hi i have a form in access. on that form it has two fields with different Times.
I want access in VBA to lookup in a table all the records that fall between the two times.

This returns a debug fault
Dim newvar As Variant

newvar = DLookup("[Time]", "tblBooked", "[Time] Between [txtNOW] And [txtNOWplusONE]")
andybrookeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Try this:

newvar = DLookup("[Time]", "tblBooked", "[Time] Between #" & [txtNOW] & "# And #" & [txtNOWplusONE] & "#")

mx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andybrookeAuthor Commented:
Hi I tried that code but i now get the following error message.
"Run-time error '2001':
You canceled the previous operation.
Here is a copy of the code:

Private Sub Form_Timer()
Dim newvar As Variant
newvar = DLookup("[HoursFrom]", "tblResources", "[HoursFrom] Between #" & [txtNOW] & "# And #" & [txtNOWplusONE] & "#")

End Sub
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
If either txtNOW and/or txtNOWplusONE happen to be Null, you will get this error.... ?

mx
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Why exactly do the normal values in these text boxes look like ?

mx
0
andybrookeAuthor Commented:
Hi. yes you were right the 1st time.... I stupidly had the table name spelt wrong
Thanks
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
"Hi. yes you were right the 1st time.... I stupidly had the table name spelt wrong
Thanks"

You are welcome ...

mx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.