Solved Picture on form not updating as it should

murray83

Games Collector
Local time
Today, 00:23
Joined
Mar 31, 2017
Messages
845
I have a simplish database whch i have made to keep track of my game collection ( and yes there are other optiuons but none did what i wanted )

so i have a simple search which in the below attached pictures you can see is my error and reason for this post, as i searched for the game 688 and all details appeard but the game cover was for APB

but then when i remove APB from the table as shown below it works, but it is running of the ID number so I dont know why it picks the wrong image

please help and cheers
 

Attachments

  • right.png
    right.png
    165.2 KB · Views: 330
  • wrong.png
    wrong.png
    138.1 KB · Views: 299
  • wrong1.png
    wrong1.png
    93.3 KB · Views: 329
  • GD 2020.zip
    GD 2020.zip
    1.1 MB · Views: 340
Took me forever to figure out.
Remove the ControlSource left in the image control. Should be unbounded.
 
Star, cheers
 
FYI to make this much easier. Use a bound image control.
Save all images using the ID number.
Have a Settings table where you can store and change the default path to the folder. Store all images in a folder. Put that path in your settings table.
Now you can make a query that concatenates the path and the image id. And voila the image appears. Super flexible and no really code needed. Also these are pretty small images but will take up a lot of size in your db. Also I do not think it is portable if you need to create a new db or the db crashes.
 
FYI,
If you plan to put the folder into the same folder as the database then you do not even need the settings table. You can pull the current project directory in code and then reference the subfolder.
 
ok but could i just not name the pics the same as ID number ?

and what if you dint mind would the code look like ( using the best air code/back of fag packet )
 
You can use a name like you have. Keep names short and no spaces or character and unique. I can give you a demo. Gallery is nice for a few images but painful for that many
 
Sorry. I forgot to post this thread.
Take a look. There is a function in the module. And I did a form in continuous view. Using the function is not as efficient as a pure sql example but gave a little more flexibility here. There is a form FrmDemo too that show continuous view.
 

Attachments

This is an interesting solution.. so in the demo form (the continuous form), there is no vba code. the control source (object Image9) is ImagePath.

How does it know when to call in the module (mdlImages) to get the ImagePath information?
 
I am not even sure what you are looking at because that demo is a mess. I forgot to provide the folder of demo images

Here is how I would do it.
1. Inside the folder where you keep the db add a child folder for cover art called CoverArt
2. Put images in there and add two images one Image to tell the user that there is no image data. One to tell the user there is a name but no matching file.
3. In the table save the names of the images without a path. You will get the path from code
data.PNG

4. create the function where you provide an ID and get the correct path. Show no image if no name provided, bad name if no file found with that name.

Code:
Public Function GetImagePath(ByVal DataID As Long, Optional AlertBadName = False)
  Dim ImageFolder As String
  Dim FileExists As String
  Dim imageName As String
  Dim ImagePath As String
 
  Const FolderName = "CoverArt"
  Const BadImageName = "BadName.png"
  Const NoImageName = "NoImage.png"
  imageName = getImageName(DataID)
  If imageName = "" Then imageName = NoImageName
  ImageFolder = CurrentProject.Path & "\" & FolderName & "\"
  ImagePath = ImageFolder & imageName
  Debug.Print ImagePath
  FileExists = Dir(ImagePath)
 
  If (FileExists = "") And imageName <> NoImageName Then
    If AlertBadName Then MsgBox "There is no file with name " & ImagePath, vbInformation
    Debug.Print "There is no file with name " & ImagePath, vbInformation
    GetImagePath = ImageFolder & BadImageName
  Else
    GetImagePath = ImagePath
  End If
End Function

Public Function getImageName(DataID As Long) As String
   getImageName = Nz(DLookup("coverimage", "T_data", "Id = " & DataID), "")
End Function

5. Use this function in a query for the form
query.PNG

6. Bind the image control to the image path. That control requires no code if it has a path.
7. Images.
Populous has a name but no file matches that name. Different then those without a name.
images.PNG
 

Attachments

Users who are viewing this thread

Back
Top Bottom