Solved If a record is null (1 Viewer)

murray83

Games Collector
Local time
Today, 13:45
Joined
Mar 31, 2017
Messages
728
Hi Folks

trying to get a picture to display, pictures will be held in the DB in a gallery. If no image present then just want it to display the text like shown in attached image and also one with no image

but when i do try search for one with no image, get the ol' invalid use of null error

this is my current code

Code:
Private Sub cmbWho_AfterUpdate()

Me.txtPlatform = DLookup("[Platform]", "[T_Data]", "[ID] = " & Me.[cmbWho])                   'inputs Platform
Me.txtYear = DLookup("[Released]", "[T_Data]", "[ID] = " & Me.[cmbWho])                       'inputs Release Year
Me.txtRegion = DLookup("[Region]", "[T_Data]", "[ID] = " & Me.[cmbWho])                       'inputs Region
Me.imgCover.Picture = DLookup("[CoverImage]", "[T_Data]", "[ID] = " & Me.[cmbWho])            'inputs Cover of Game Selected, If One Present

but i know i have to do something like isnull, have tried a search on google and here, but ones i found where checking if text was around, suggestions on this would help

cheers all
 

Attachments

  • no image.png
    no image.png
    106.3 KB · Views: 105
  • with image.png
    with image.png
    158.2 KB · Views: 95
  • GD 2020.accdb
    4.6 MB · Views: 113

June7

AWF VIP
Local time
Today, 05:45
Joined
Mar 9, 2014
Messages
5,423
I created an image that has text "NO IMAGE AVAILABLE" and associate that with record.

Since form is bound to table, why not just have code apply filter to form or go to record? Bind textboxes to fields. Set as Locked if you don't want to allow edits.
 
Last edited:

murray83

Games Collector
Local time
Today, 13:45
Joined
Mar 31, 2017
Messages
728
I created an image that has text "NO IMAGE AVAILABLE" and associate that with record.

tried that with a blank image but then it just kept showing the same blank image even though have one image for 688 attack sub
 

June7

AWF VIP
Local time
Today, 05:45
Joined
Mar 9, 2014
Messages
5,423
If image is associated with record, then it should show.

Maybe you read my previous post before I edited it.
 

murray83

Games Collector
Local time
Today, 13:45
Joined
Mar 31, 2017
Messages
728
Maybe you need the NZ function


like this

Code:
Private Sub cmbWho_AfterUpdate()

Me.txtPlatform = DLookup("[Platform]", "[T_Data]", "[ID] = " & Me.[cmbWho])                   'inputs Platform
Me.txtYear = DLookup("[Released]", "[T_Data]", "[ID] = " & Me.[cmbWho])                       'inputs Release Year
Me.txtRegion = DLookup("[Region]", "[T_Data]", "[ID] = " & Me.[cmbWho])                       'inputs Region
Me.imgCover.Visible = True                                                                    'shows image
Me.imgCover.Picture = Nz(DLookup("[CoverImage]", "[T_Data]", "[ID] = " & Me.[cmbWho]), "")    'inputs Cover of Game Selected, If One Present

End Sub

edit with updated DB has image for Sonic and kunckles and 688 to test
 

Attachments

  • GD 2020.accdb
    3.9 MB · Views: 101

Isaac

Lifelong Learner
Local time
Today, 06:45
Joined
Mar 14, 2017
Messages
8,738
Sounds like a sensible approach. Glad you got it working. (if I understood your last post right).
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:45
Joined
Sep 21, 2011
Messages
14,041
I did and thanks for the Nz idea
FWIW
I think June7's idea is better, as a user cannot identify whether an image exists or just a problem with your code?
You can combine that with the NZ() function?
 
Last edited:

murray83

Games Collector
Local time
Today, 13:45
Joined
Mar 31, 2017
Messages
728
smart and done

try half life
 

Attachments

  • GD 2020.accdb
    3.8 MB · Views: 115

murray83

Games Collector
Local time
Today, 13:45
Joined
Mar 31, 2017
Messages
728
but one last thing, if i put in the coverimage part of the table "NoImage", which is the name of the image in the gallery for when i have no image yet, for the rest of my records

all it shows is the NoImage even if i had an image, why ??
 

June7

AWF VIP
Local time
Today, 05:45
Joined
Mar 9, 2014
Messages
5,423
VBA to set value of an UNBOUND control will show same info for all records. Unless you use Single view form and code in Current event to re-set values for each record.

Why don't you consider suggestion in post 3?
 

murray83

Games Collector
Local time
Today, 13:45
Joined
Mar 31, 2017
Messages
728
VBA to set value of an UNBOUND control will show same info for all records. Unless you use Single view form and code in Current event to re-set values for each record.

Why don't you consider suggestion in post 3?
sorry i have read that one again, so you would have an extra text box which had "NO IMAGE"

also for current code see attached
 

Attachments

  • GD 2020.accdb
    3.8 MB · Views: 109

June7

AWF VIP
Local time
Today, 05:45
Joined
Mar 9, 2014
Messages
5,423
No, I would not have another textbox - I would display "NO IMAGE AVAILABLE" image. Your code references a variable - NoImage - but does not declare nor set it anywhere. If image path\name for "NoImage" is in field, there is no need for Nz() because every record would have an image reference. If field truly is null then you cannot just reference "NoImage" name, need full path to this image, like:

Me.imgCover.Picture = Nz(DLookup("[CoverImage]", "[T_Data]", "[ID] = " & Me.[cmbWho]), "C:\folderpath\NoImage.jpg")

Still not doing what I suggested. Have you considered it?
 

murray83

Games Collector
Local time
Today, 13:45
Joined
Mar 31, 2017
Messages
728
I created an image that has text "NO IMAGE AVAILABLE" and associate that with record.

Since form is bound to table, why not just have code apply filter to form or go to record? Bind textboxes to fields. Set as Locked if you don't want to allow edits.

i have read it at least three times and im not sure i understand

would you mind showing what you mean just use my previous attached db
 

June7

AWF VIP
Local time
Today, 05:45
Joined
Mar 9, 2014
Messages
5,423
Nothing unusual about my suggestion. A normal bound form and bound controls. Code (using unbound combobox to enter search criteria) would either set form Filter or go to record. Then form could be in Single, Continuous, or Datasheet and navigate records.

Oh, I have never used Picture property for dynamic display of images - I use image control ControlSource property. Bind to field with image path or build the path with expression in ControlSource, like: =CurrentProject.Path & "\Images\" & [CoverImage] & ".jpg"). Might find this discussion of interest https://www.accessforums.net/showthread.php?t=73766

You have code setting Picture property but then ControlSource is also set to field. That appears to be conflict.
 
Last edited:

Users who are viewing this thread

Top Bottom