Results 1 to 6 of 6
  1. #1
    seth1685 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    10

    DLookup issue

    Ok, so this piece of code is supposed to take an array:

    "4514, 4234, 2345" (RS!PROG)

    split it:

    4514 (txtPCODE)

    lookup the description that goes with that Module Number from tblPROG:

    4514 (txtPCODE) - BA Geography (txtPDESC)

    then iterate through the array to populate lstPROGS:

    BA Geography
    BSC Maths
    MA Physics

    But what I am getting is:

    BA Geography
    BA Geography
    BA Geography

    Any ideas?



    I used an almost identical piece of code but without the DLOOKUP to populate another list with module codes and that worked fine.

    Code:
     'Check there are programmes assigned to the selected EE
    If Not IsNull(Rs!PROG) Then
     
    'If there are, take the string of programmes, split them where they are divided by ","
    a = Split(Rs!PROG, ",")
     
    For i = LBound(a) To UBound(a)
     
    'Print each Programme Description in full
    lstPROGS.AddItem DLookup("txtPDESC", "tblPROG", a(i))
     
    Next
     
    'List "None" if none are assigned
    Else
     
    lstPROGS.AddItem ("None")
     
    'End of populating the programme list
    End If
    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You don't have the proper syntax for the criteria, which would be "FieldName = Value"; you simply have "Value". See if this helps:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    seth1685 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    10
    Ok, so now i have

    lstPROGS.AddItem DLookup("txtPDESC", "tblPROG", "txtPCODE = 'a(i)'") at line 10

    but I'm getting error, invalid use of null

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Does this work?

    lstPROGS.AddItem DLookup("txtPDESC", "tblPROG", "txtPCODE = '" & a(i) & "'")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    seth1685 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2012
    Posts
    10
    Fantastic! Had to add in trim, but working perfectly now!

    Thanks so much.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. DLookUp Help
    By ThaGreenMoose in forum Forms
    Replies: 10
    Last Post: 06-15-2011, 12:08 PM
  2. DLookup help
    By denners05 in forum Access
    Replies: 1
    Last Post: 06-11-2011, 12:55 PM
  3. Easy DLookup Issue
    By Niki in forum Access
    Replies: 7
    Last Post: 05-25-2011, 03:00 PM
  4. Tough form issue that uses DLookup's
    By Solola in forum Forms
    Replies: 3
    Last Post: 03-15-2011, 01:25 PM
  5. Dlookup
    By janjan_376 in forum Access
    Replies: 20
    Last Post: 07-07-2009, 07:40 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