[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1227
  • Last Modified:

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]")
0
andybrooke
Asked:
andybrooke
  • 4
  • 2
1 Solution
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
Try this:

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

mx
0
 
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 MVP, Access and Data Platform)Commented:
If either txtNOW and/or txtNOWplusONE happen to be Null, you will get this error.... ?

mx
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
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 MVP, Access and Data Platform)Commented:
"Hi. yes you were right the 1st time.... I stupidly had the table name spelt wrong
Thanks"

You are welcome ...

mx
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now