Results 1 to 10 of 10
  1. #1
    gsantacruz is offline Novice
    Windows Vista Access 2003
    Join Date
    Oct 2010
    Posts
    3

    dlookup help

    Hello!

    Please bear with me i'm a total rookie.

    I am trying to prevent operators from filling out my "inspections log" form before they have entered the hours the are working that day in the "inspectors' hours" table through a form also called "inspectors' hours".

    in order to do so, i am using a dlookup function on the before update event in my "hours" field in the "inspections log" form that looks up if there are any hours entered for that day for that operator in the "inspectors' hours" table. This is what I got:

    Private Sub Inspector_Name_BeforeUpdate(Cancel As Integer)
    Dim icount As Long
    icount = Nz(DLookup("Hours", "Inspectors' Hours", "Inspector=" & [Inspector] & " And Date= #" & [Date] & "#"), 0)
    If icount = 0 Then
    MsgBox "Please enter the hours you are working today before filling the inspections log."
    Cancel = True
    Undo


    End If
    End Sub

    I am having all kinds of trouble with it. I am getting the "Compile Error: External name not defined" error message when I run the nz(dlookup) function, but it works fine when i take out the date part...

    any ideas?

    Thank you!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Try putting brackets around [Date]. It is a reserved word and should not be used for a field name. Is [Inspector] a numeric field?

  3. #3
    gsantacruz is offline Novice
    Windows Vista Access 2003
    Join Date
    Oct 2010
    Posts
    3
    hello RuralGuy, and thank you for your response.

    I have tried the brackets, still nothing!

    Inspectors is a text field...

    i am basically trying to get the dlookup function to check if there is an entry for hours in the inspectors' hours table, for which it needs to look for the name and date entered in the form. i think i am closer with this, but it still doesnt work:

    Private Sub FF_Change()
    Dim icount As Long
    icount = Nz(DLookup("Hours", "Inspectors' Hours", "[Inspector] = " & Forms![Inspections Log]![Inspector_Name] & " And [Date] = #" & Forms![Inspections Log]![Date] & "#"), 0)
    If icount = 0 Then
    MsgBox "Please enter the hours you are working today before filling the inspections log."
    Cancel = True
    Undo
    End If
    End Sub

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I think RuralGuy is busy on something.
    would you try following before RuralGuy comes back and gives a good advise?

    icount = Nz(DLookup("Hours", "[Inspectors' Hours]", "[Inspector] = '" & Forms![Inspections Log]![Inspector_Name] & "' And [Date] = #" & Forms![Inspections Log]![Date] & "#"), 0)

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It looks like Weekend00 gave some pretty good advice. Let us know how it works.

  6. #6
    gsantacruz is offline Novice
    Windows Vista Access 2003
    Join Date
    Oct 2010
    Posts
    3

    yaaay!!!

    Thank you, It works perfectly!!!

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That's great! Are you ready to follow the link in my sig and mark this thread as Solved?

  8. #8
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by RuralGuy View Post
    That's great! Are you ready to follow the link in my sig and mark this thread as Solved?
    Hey, do you have this line store in the database somewhere and just call it with a script whenever something gets solved? :laugh: This post is a national pastime with you.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Adam: Would you believe I type it each and every time?

  10. #10
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by RuralGuy View Post
    Adam: Would you believe I type it each and every time?
    You bet I would!

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

Similar Threads

  1. DLookup example
    By pkstormy in forum Code Repository
    Replies: 1
    Last Post: 07-16-2012, 09:52 AM
  2. DLookup()
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 09-15-2010, 07:20 AM
  3. Need help with dlookup.
    By Keith in forum Database Design
    Replies: 8
    Last Post: 05-24-2010, 06:28 PM
  4. Dlookup??
    By Vikki in forum Access
    Replies: 4
    Last Post: 02-16-2010, 07:59 AM
  5. Dlookup
    By janjan_376 in forum Access
    Replies: 20
    Last Post: 07-07-2009, 07:40 AM

Tags for this Thread

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