Results 1 to 9 of 9
  1. #1
    BRV is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    29

    What is wrong with my DLookup?

    I've been working hard to get this straight. I've tried it a bunch of different ways. Please help!

    I have a report based on the table (Inventory). In the report I have an empty image placeholder (img.Logo). This table also contains a field (Make).
    In another table (tblLogos), I have 2 fields (Manufacturer) & (txtPath).
    (Make) & (Manufacturer) are related. In my form, the rowsource for (Make) is a query from (Manufacturer) in the (tblLogos). (I'm not sure if any of this is related to the problem)

    In the Report OnLoad Event, I'm attempting to use Dlookup to compare the Manufacturer to the Make, Find the record in which they match, and return the string - which is a file path to the image to the .Picture property of the imgLogo placeholder. In all the different ways I've tried, I've seen many different errors, but currently:
    Run-time error '2428':
    You entered an invalid argument in a domain aggregate function.

    Code:
    'Load logo image based on make selected in current record
    Dim logoPath As String
    logoPath = DLookup("txtPath", tblLogos, "[Manufacturer] = & [Inventory]![Make]")
    imgLogo.Picture = logo_path
    Also, when in debug mode (which I know little about), if I mouse over "tblLogos" in the code, it brings up "tblLogos=Empty" in the pointer tips.

  2. #2
    BRV is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    29
    I think I fixed some messed up syntax. This is what I have now:
    Code:
    Private Sub Report_Load()
    'Load logo image based on make selected in current record
    Dim logoPath As Variant
    logoPath = DLookup("txtPath", "tblLogos", "Manufacturer" = "Inventory.Make")
    imgLogo.Picture = logoPath
    End Sub
    Better? I Don't know. Now I'm getting "invalid use of Null" at the imgLogo.Picture = logoPath

    I'll be looking forward to your responses!

  3. #3
    CraigDolphin is offline Competent Performer
    Windows XP Access 2000
    Join Date
    Apr 2009
    Location
    Custer, WA, USA
    Posts
    125
    if the data in the Manufacturer and Make fiels are numeric, then you would use:
    logoPath = DLookup("txtPath", "tblLogos", "[Manufacturer] =" & [Make])
    if they are text strings then you'd use:
    logoPath = DLookup("txtPath", "tblLogos", "[Manufacturer] ='" & [Make] & "'")

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Just change to have an alternate path for a default image which shows if there is no actual image available.
    Code:
    Private Sub Report_Load() 
    'Load logo image based on make selected in current record 
    Dim logoPath As String
     
    Const AltDefault As String = "C:\WhateverPathYouHaveAlternateAt.jpg"
     
    logoPath = Nz(DLookup("txtPath", "tblLogos", "Manufacturer = " & Chr(34) & Inventory.Make & Chr(34)), AltDefault)
    imgLogo.Picture = logoPath 
    End Sub
    Last edited by boblarson; 11-02-2011 at 03:07 PM. Reason: get rid of forum formatting code/add quotes

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Try
    DLookup("txtPath", "tblLogos", "Manufacturer = '" & Inventory.Make & "'")


    Oops I see others have posted while I was typing.....

  6. #6
    BRV is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    29
    Ok, I've tried this:

    Quote Originally Posted by CraigDolphin View Post
    if the data in the Manufacturer and Make fiels are numeric, then you would use:
    logoPath = DLookup("txtPath", "tblLogos", "[Manufacturer] =" & [Make])
    if they are text strings then you'd use:
    logoPath = DLookup("txtPath", "tblLogos", "[Manufacturer] ='" & [Make] & "'")
    And this:

    Quote Originally Posted by orange View Post
    Try
    DLookup("txtPath", "tblLogos", "Manufacturer = '" & Inventory.Make & "'")


    Oops I see others have posted while I was typing.....

    Neither works.


    Quote Originally Posted by boblarson View Post
    Just change to have an alternate path for a default image which shows if there is no actual image available.
    Code:
    Private Sub Report_Load() 
    'Load logo image based on make selected in current record 
    Dim logoPath As String
     
    Const AltDefault As String = "C:\WhateverPathYouHaveAlternateAt.jpg"
     
    logoPath = Nz(DLookup("txtPath", "tblLogos", "Manufacturer = " & Chr(34) & Inventory.Make & Chr(34)), AltDefault)
    imgLogo.Picture = logoPath 
    End Sub
    Having an alt image doesn't really do me any good in this particular situation. The logos must match the make/manufacturer or the report is worthless.

    I'm concerned that there's something in the "structure" of this db that I did wrong. I'm also wondering if there is a better function to find the right record.

    Any other ideas?

  7. #7
    BRV is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    29
    Ok. I got it now.

    The problem was that the "Make" Field was not on the report. I was having trouble calling it from the table. The simplest solution for me was simply to add the field and set the visible property to no.

    It works perfectly now.

    I cleaned it up and added a msgbox for if it doesn't return a path:
    Code:
    Private Sub Report_Load()
    Dim logoPath As String
    'Load logo image based on make selected in current record
    logoPath = Nz(DLookup("txtPath", "tblLogos", "[Manufacturer] ='" & [Make] & "'"))
    If LenB(logoPath) <> 0 Then
    imgLogo.Picture = logoPath
    Else
    MsgBox "There is no logo set up for this manufacturer. Check the Make or set up a logo", vbExclamation + vbOKOnly, "Missing Logo Image"
    End If
    logoPath = vbNullString
    End Sub

    Thank you all for your help!

  8. #8
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by BRV View Post
    Having an alt image doesn't really do me any good in this particular situation. The logos must match the make/manufacturer or the report is worthless.
    Just an FYI -

    If you are opening only ONE manufacturer report at a time then it is no issue. But if you are opening a report that has several together and you wanted to have their logo on their page, and there wasn't one available for one of them, then in my experience it ends up showing the last assigned one instead. Having a default image (1 pixel of white) is a good way to avoid that.

  9. #9
    BRV is offline Novice
    Windows XP Access 2007
    Join Date
    Oct 2011
    Posts
    29
    Quote Originally Posted by boblarson View Post
    Just an FYI -

    If you are opening only ONE manufacturer report at a time then it is no issue. But if you are opening a report that has several together and you wanted to have their logo on their page, and there wasn't one available for one of them, then in my experience it ends up showing the last assigned one instead. Having a default image (1 pixel of white) is a good way to avoid that.
    Hey Bob,
    I see what you mean. In this instance, the report will be for a single record, so I should be fine, but what you say makes sense.

    Thanks for your help!

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

Similar Threads

  1. Big file... what's wrong?
    By lyborko in forum Access
    Replies: 3
    Last Post: 07-17-2011, 12:52 AM
  2. What's wrong!
    By khalid in forum Programming
    Replies: 15
    Last Post: 06-27-2011, 06:38 AM
  3. What is wrong with this IFF?
    By bburton in forum Reports
    Replies: 2
    Last Post: 03-16-2011, 10:42 AM
  4. What is wrong with this code?
    By nkenney in forum Forms
    Replies: 2
    Last Post: 11-16-2009, 03:04 PM
  5. What am I doing wrong?
    By brandon in forum Access
    Replies: 2
    Last Post: 08-03-2008, 10:26 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