Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108

    DLookup function help ,Error : #NAME

    I have a continuous form and I would like to add in a textbox in the form to display the date of the loaded data



    I want to display "DATA FOR PERIOD 2015-11"
    Since, I can't use subform in my continuous form. I'm trying to use a D look up function because I'm using another record source for my Form.
    However , I keep getting error #NAME.

    Anyone could help me ?
    Thanks in advance
    Code:
    =DLookUp("[LOAD_PERIOD]","[Load_Date]","[LOAD_PERIOD]"="DATA FOR PERIOD " & Year([LOAD_PERIOD]) & "-" & Format(Month([Load_Period])))

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Why are you using DLookup to look up load period when you already have the load period value?

    You are using [Load_Date] in the argument for domain (table or query). You have a table named Load_Date?


    Maybe you just need:

    ="DATA FOR PERIOD " & Format([Load_Period], "yyyy-mm")
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Your DLookup doesn't look right. Do you have a table or query called "Load_Date"? If not, that is a possible source of the error - the DLookup is trying to look up data from a field called "Load_Period" in a table or query called "Load_Date". The where clause in the DLookup doesn't make sense either - it should specify which record the DLookup should retrieve data from, but I can't see how it will.

    Is there a form field (control) which contains the data you want to use in the DLookup WHERE clause?

  4. #4
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by John_G View Post
    Your DLookup doesn't look right. Do you have a table or query called "Load_Date"? If not, that is a possible source of the error - the DLookup is trying to look up data from a field called "Load_Period" in a table or query called "Load_Date". The where clause in the DLookup doesn't make sense either - it should specify which record the DLookup should retrieve data from, but I can't see how it will.

    Is there a form field (control) which contains the data you want to use in the DLookup WHERE clause?

    I do have a query called "Load_Date"

    My initial D look up is =DLookUp ( "[Load_Period]", "[Load_Date]" , )
    However I get this value " 01/11/15"

    So I'm trying to do is to display this "DATA FOR PERIOD 2015-11"
    that's why I tried to put this as my criteria (]","[LOAD_PERIOD]"="DATA FOR PERIOD " & Year([LOAD_PERIOD]) & "-" & Format(Month([Load_Period])))

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    The third argument is for filter criteria, like the WHERE clause in SQL statement. Where you are concatenating a string needs to be a field from the source table/query and a parameter to search for. What you need is like:

    ="DATA FOR PERIOD " & Format(DLookup("[Load_Period]", "[Load_Date]", "[some fieldname in the query] = some value here"), "yyyy-mm")

    The filter criteria is optional. Without it, the DLookup will return value from unspecified (maybe first, maybe not) record in the dataset.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Quote Originally Posted by June7 View Post
    The third argument is for filter criteria, like the WHERE clause in SQL statement. Where you are concatenating a string needs to be a field from the source table/query and a parameter to search for. What you need is like:

    ="DATA FOR PERIOD " & Format(DLookup("[Load_Period]", "[Load_Date]", "[some fieldname in the query] = some value here"), "yyyy-mm")

    The filter criteria is optional. Without it, the DLookup will return value from unspecified (maybe first, maybe not) record in the dataset.
    Ahh . I got it Thank you so much
    By the way , is there a way to make my text box(load date) value permanent ?
    My form have a few combo boxes and when the combo box value is changed , the whole page will be refreshed. Thus , the text box(load date) will be refreshed as well ,

    Is there any way to make it like permanent ?
    I don't want my text box to be refreshed unless when I re-open the form ?

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Sorry, don't really understand the question. If textbox is bound to a field or has dynamic expression, it will change as the data changes.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    How to make the textbox(load_date) not dynamic ?
    cos if I change my combo box value and it does not retrieve/display any data .

    The textbox(load_date) will be not displayed

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Sorry, none of that makes sense to me. I don't know your data structure enough nor what you are trying to accomplish to advise.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    I want to unbound my textbox instead ..

    I'm trying to do this instead but still getting error #NAME

    Code:
    Private Sub getLoadDate()
    Me.RecordSource = "SELECT * FROM Setting"
    Me!txtload_period.ControlSource = "LOAD_PERIOD"
    End Sub

    Code:
    Private Sub Form_Load()
        DoCmd.Maximize
    
        
        getLoadDate
        
    End Sub

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Why are you using VBA to set form and textbox properties? Why don't you just set these properties in form design view?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    In this form , I have unbound combo boxes .
    So when I select a value from the combo box and if It does not retrieve anything ,
    The load date textbox will not be displayed .

    This is the reason why I want to unbound my textbox.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Don't really understand that reasoning.

    But, try . instead !.

    Me.txtload_period.ControlSource = "LOAD_PERIOD"
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    fluffyvampirekitten is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jun 2015
    Posts
    108
    Click image for larger version. 

Name:	1.JPG 
Views:	16 
Size:	24.7 KB 
ID:	23454

    When I click on Category "POTENTIAL DUP"
    It will display the "LOAD DATE"

    When I click on Category "REPEATED"
    It does not display the " LOAD DATE"

    Click image for larger version. 

Name:	2.JPG 
Views:	16 
Size:	30.1 KB 
ID:	23455

    I tried to do the bound and unbound text box, the result are still the same . Why is that so ?
    I don't know what to do already
    Last edited by fluffyvampirekitten; 01-19-2016 at 12:09 AM. Reason: unbound syntax is solved.

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Why are you using code to set ControlSource property of txtload_period with a field name? If that field is not in the form RecordSource, will then get #NAME error in textbox.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. DLookup Function
    By Alex Motilal in forum Programming
    Replies: 8
    Last Post: 08-14-2014, 01:15 PM
  2. DLOOKUP function
    By tariq1 in forum Programming
    Replies: 5
    Last Post: 07-17-2012, 04:22 PM
  3. DlookUp Function.
    By cap.zadi in forum Forms
    Replies: 11
    Last Post: 09-22-2011, 12:56 PM
  4. DLookUp function giving invalid use of null error
    By shubhamgandhi in forum Programming
    Replies: 4
    Last Post: 07-21-2011, 06:04 PM
  5. Replies: 2
    Last Post: 11-02-2009, 10:14 PM

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