Results 1 to 7 of 7
  1. #1
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368

    Dlookup problem

    I am trying to Dlookup two fields with dates in them. If the Dlookup returns that today is in the range (e.g. 06-03-2015 in the first field and 10-03-2015 in the second) then i want the system to display a messagebox when im opening up a form.
    If today is not in the range then the messagebox should not pop up.

    Code:
    If DLookup("HollidayFrom", "tblBuildingManager", "[HollidayFrom] >= Date()") And DLookup("HollidayTill", "tblBuildingManager", "[HollidayTill] <= Date()") Then
    msgBox "A building manager is on holliday"
    end if
    The table looks like this :

    BuildingManager ManagerID Phone1 Phone2 Phone3 HollidayFrom HollidayTill
    George Bush 1 06-11111111 06-11111112 06-11111113 1-4-2015 9-4-2015
    Bill Clinton 2 06-22222222 06-11111114 06-11111115 30-8-2015 19-9-2015


  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    You have DATE() inside the dbl quote. It must be outside it to resolve into a date.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    I think your <> are mixed up. You may have an international dates issue, but perhaps not with Date() inside the quotes. If so:

    http://allenbrowne.com/ser-36.html#Format
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,841
    You need to compare your dlookup with something otherwise you will get

    if 02/04/2015 then
    ...

    dlookup returns null if no record is found so use

    if not isnull(dlookup(....)) then
    ....

    Alternatively you could use dcount and compare it with a value - also you can use between to simplify the code a bit . Having Date() within the quotation marks shouldn't matter since it is a function

    Code:
    If DCount("*", "tblBuildingManager", "Date() between [HollidayFrom]  and [HollidayTill]") >0 Then
        msgBox "A building manager is on holliday"
    end if

  5. #5
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Thanks Ajax, your Dcount works flawlessly !

    Now im trying to expand this by informing the user wich building manager is on holliday.
    Could you point me in the right direction for that one as well ?

    Thanks for your time mates !

  6. #6
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,841
    Now im trying to expand this by informing the user wich building manager is on holliday
    You would be better to state your final objective rather than moving step by step

    Code:
    Dim Person as string
    person=nz(DLookup("[BuildingManager]", "tblBuildingManager", "Date() between [HollidayFrom]  and [HollidayTill]"),"")
     if person<>"" Then
        msgBox person & " is on holliday"
    end if
    Note you will need a completely different solution if more than one manager can be away at the same time and you need to list them

  7. #7
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    You are completely right, my appologies mate.
    Your solution works like a charm and i thank you !

Please reply to this thread with any new information or opinions.

Similar Threads

  1. dlookup problem
    By sdel_nevo in forum Programming
    Replies: 7
    Last Post: 08-19-2014, 08:20 AM
  2. Problem with DlookUp
    By zylosan in forum Programming
    Replies: 10
    Last Post: 10-18-2013, 07:46 AM
  3. Dlookup problem
    By Terava in forum Access
    Replies: 5
    Last Post: 04-29-2013, 11:05 PM
  4. DLookUP problem
    By Symlink in forum Access
    Replies: 7
    Last Post: 03-28-2013, 11:03 AM
  5. Using Dlookup problem
    By Lupson2011 in forum Access
    Replies: 5
    Last Post: 12-07-2011, 10:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums