DLookup problem

lmcc007

Registered User.
Local time
Today, 10:23
Joined
Nov 10, 2007
Messages
635
I am trying to say that if the record has an image attached display the image icon and if not display nothing. The code displays the icon on each record. Here's the code:

Code:
Private Sub Form_Load()

    If IsNull(DLookup("EventAttachment", "Event", "EventID = " & Me.txtEventID)) Then
        Me.Image123.Visible = False
    Else
        Me.Image123.Visible = True
    End If
    
End Sub

Any help is appreciated!
 
Does it throw an error?

Why don't you Msgbox the DLookup() to see what the value is when it has an attachment and when it doesn't (if it works)?
 
Does it throw an error?

Why don't you Msgbox the DLookup() to see what the value is when it has an attachment and when it doesn't (if it works)?

No, I do not get an error. It just displays all the images for each record whether the record has an error or not.

How do you Msgbox the DLookup()?

Thanks!
 
I'm sure you know what the Msgbox does? It displays a value.
 
Put this in the On Current Event of your form:

Msgbox DLookup("EventAttachment", "Event", "EventID = " & Me.txtEventID)

Note the values that appear, if any. For one that doesn't have an attachment it should have a particular value. I'm not 100% sure if it returns Null which is probably why your code isn't working.
 
Put this in the On Current Event of your form:

Msgbox DLookup("EventAttachment", "Event", "EventID = " & Me.txtEventID)

Note the values that appear, if any. For one that doesn't have an attachment it should have a particular value. I'm not 100% sure if it returns Null which is probably why your code isn't working.

See I wouldn't have guess that! Still learning.

Anyway, when there are no attachment the message box is blank; where there is an attachment the message box displays the attachment name. And, the icon still displays either way.

Thanks!
 
In that case it's not returning Null, but a zls. So your code will be:
Code:
Me.Image123.Visible = (Len(DLookup("EventAttachment", "Event", "EventID = " & Me.txtEventID) & "") = 0)
 
In that case it's not returning Null, but a zls. So your code will be:
Code:
Me.Image123.Visible = (Len(DLookup("EventAttachment", "Event", "EventID = " & Me.txtEventID) & "") = 0)

Nope, not working. When I go to the record that has an attachment, it highlight all the other records until I move off the one that has an attachment.

Also, I tried putting zero in as the criteria on a query and get the following error message: Data type mismatch in criteria expression.

Also, this is an attachment field in the table.

In another form I am using a text box (using Winding to get my character) and it works fine. Here is the code I am using:

Code:
=IIf([EventNoteData] Is Not Null,"!",Null)

The reason I am not using a text box again because I am need a paperclip picture.
 
Oops... this:
Code:
Me.Image123.Visible = (Len(DLookup("EventAttachment", "Event", "EventID = " & Me.txtEventID) & "") [COLOR=Red][B]<>[/B][/COLOR] 0)
Make sure the code is in the On Current event of the form, not On Load.
 
Oops... this:
Code:
Me.Image123.Visible = (Len(DLookup("EventAttachment", "Event", "EventID = " & Me.txtEventID) & "") [COLOR=Red][B]<>[/B][/COLOR] 0)
Make sure the code is in the On Current event of the form, not On Load.

Still displaying the paperclip image on all the records.
 
Use the Msgbox to test the Len() and see what the value is for when it has no clip.
 
If it's returning True and False then it should hide and unhide the image control. There might be other code overriding this.

Let's see your db.
 
If it's returning True and False then it should hide and unhide the image control. There might be other code overriding this.

Let's see your db.

Well, I wish I could post this db on web, but he said no--the paper clip image is not that important. I guess I have to scrap this and look for a character I can use with a text box to replace the paperclip image.

Thanks for your help!
 
Is there any other code that is interferring with the imagecontrol?
 
Is there any other code that is interferring with the imagecontrol?

No.

You know I read somewhere about image control problems or something. When you read so many books and stuff you forget a lot of it or where you saw it.

Anyway, attached is an example of what I am trying to do--sort of. I got this from this site.
 

Attachments

Throw up a quick sample db with some images and post it.
 
Throw up a quick sample db with some images and post it.

It has to have something to do with the image. I even change the form from Continuous to Single and the image operated the same.

Now, I went and used a textbox and put this in the ControlSource:

Code:
=IIf([EventAttachment] Is Not Null,".",Null)

It works!

I will just stick with the text and use an asterik.

Thanks!
 
Hang on a sec. Are you looking to do this in a continuous form?
 

Users who are viewing this thread

Back
Top Bottom