Solved Adding attachments to a form (1 Viewer)

Momma

Member
Local time
Today, 13:31
Joined
Jan 22, 2022
Messages
114
Hi everyone. I want to add photos and documents as attachments into my Dog's Profile (frmDogProfile) I acquired code from a guy whom I did my initial Access Training with but he doesn't offer any support. I struggled a few days to get this far and I have finally ended up with two issues.
1) I manage to attach a photo into 'MyPictureFrame' which is an image box and the filename is saved in the 'MyPicture' field, but the picture does not show.
2) The document part is managed through a sub form called 'frmDocument'. I can attach any jpg files and open them, with no problem. When I try to attach any other file types, eg pdf, word, excel, I get an error. The code provides for all those file types.
I am way too inexperienced to figure out where the problem lies and would highly appreciate help from one of the amazingly talented guys in this forum.
I'm also open to any advise or examples of code that would do similar to what I have.

I might just explain the path selection. The path starts off in the directory where the database is saved.
It then creates a path similar to this: c:\Databasefolder\Entity\13\Documents - 13 is the DogID. The photo selected from 'MyPictureFrame' is saved under the DogID folder and the documents under the Documents folder.
 
Last edited:

June7

AWF VIP
Local time
Yesterday, 18:31
Joined
Mar 9, 2014
Messages
5,399
MyPicture field is not saving a picture. It is just a text field so can only save a file path/name string. There is no data in this field in the posted db.

I don't see any Attachment type fields so cannot attach any files of any type.

Use an Image control to display images (jpg, bmp, ico, gif, png) and what you are doing is right idea. I will have to do some testing.
 
Last edited:

Momma

Member
Local time
Today, 13:31
Joined
Jan 22, 2022
Messages
114
MyPicture field is not saving a picture. It is just a text field so can only save a file path/name string. There is no data in this field in the posted db.

I don't see any Attachment type fields so cannot attach any files of any type.

Use an Image control to display images (jpg, bmp, ico, gif, png) and what you are doing is right idea. I will have to do some testing.
Hi June7, thanks for your reply. I removed the data in the MyPicture field. You can attach any jpg file for testing.
 

June7

AWF VIP
Local time
Yesterday, 18:31
Joined
Mar 9, 2014
Messages
5,399
Okay, expression for the image path is using field reference [EntityID]. This field does not exist. Change to DogID.
 

Momma

Member
Local time
Today, 13:31
Joined
Jan 22, 2022
Messages
114
Okay, expression for the image path is using field reference [EntityID]. This field does not exist. Change to DogID.
I didn't see that and it seems to be the problem for that one. Thank you, you're a genius.
Will you have a look at the document sub form as well, please?
 

June7

AWF VIP
Local time
Yesterday, 18:31
Joined
Mar 9, 2014
Messages
5,399
I am getting error on code trying to load file like C:\Users\...\System\PDF.jpg in the RefreshDocImage procedure.

Do you know how to step debug code?
 
Last edited:

Momma

Member
Local time
Today, 13:31
Joined
Jan 22, 2022
Messages
114
I am getting error on code trying to load file like C:\Users\...\System\PDF.jpg in the RefreshDocImage procedure.

Do you know how to step debug code?
That is the error I'm getting as well. I'm not familiar how to step debug code.
 

June7

AWF VIP
Local time
Yesterday, 18:31
Joined
Mar 9, 2014
Messages
5,399
Time to learn. Here is one tutorial https://www.fmsinc.com/tpapers/vbacode/Debug.asp#Debugger

I have never used Picture property. I would use ControlSource property of Image control. Regardless, apparently this code is building an invalid path for system image files. You have adopted code from a tutorial site. I have no idea why it is building this path structure nor where these image files are expected to be located. I would probably embed these images into tblDocumentType table Attachment field then use expression in ControlSource to load, like: =DLookUp("Image","tblDocumentType","DocType='" & [DocumentTypeCombo].[Column](1) & "'"). Then eliminate VBA. But first have to find images you can use.
 
Last edited:

June7

AWF VIP
Local time
Yesterday, 18:31
Joined
Mar 9, 2014
Messages
5,399
The code has comment with reference to a training website URL.
' ABCD Copyright (c) 2021 by Richard Rost and AccessLearningZone.com
 

Momma

Member
Local time
Today, 13:31
Joined
Jan 22, 2022
Messages
114
Time to learn. Here is one tutorial https://www.fmsinc.com/tpapers/vbacode/Debug.asp#Debugger

I have never used Picture property. I would use ControlSource property of Image control. Regardless, apparently this code is building an invalid path for system image files. You have adopted code from a tutorial site. I have no idea why it is building this path structure nor where these image files are expected to be located. I would probably embed these images into tblDocumentType table Attachment field then use expression in ControlSource to load, like: =DLookUp("Image","tblDocumentType","DocType='" & [DocumentTypeCombo].[Column](1) & "'"). Then eliminate VBA. But first have to find images you can use.

Time to learn. Here is one tutorial https://www.fmsinc.com/tpapers/vbacode/Debug.asp#Debugger

I have never used Picture property. I would use ControlSource property of Image control. Regardless, apparently this code is building an invalid path for system image files. You have adopted code from a tutorial site. I have no idea why it is building this path structure nor where these image files are expected to be located. I would probably embed these images into tblDocumentType table Attachment field then use expression in ControlSource to load, like: =DLookUp("Image","tblDocumentType","DocType='" & [DocumentTypeCombo].[Column](1) & "'"). Then eliminate VBA. But first have to find images you can use.
Thank you for your advice, June7. I've decided to get rid of the picture frame which eliminates the error. I should've thought about that earlier 😊
 

moke123

AWF VIP
Local time
Yesterday, 22:31
Joined
Jan 11, 2013
Messages
3,834
I think you may be over complicating this .

Heres an example how I might do it.
 

Attachments

  • Files.zip
    194.9 KB · Views: 298

Momma

Member
Local time
Today, 13:31
Joined
Jan 22, 2022
Messages
114
I think you may be over complicating this .

Heres an example how I might do it.
Thanks for your advice, Moke123 but it won't work for me. I have quite a few documents that are relevant to each dog and this is the best way I can add them to a specific dog.
 

Momma

Member
Local time
Today, 13:31
Joined
Jan 22, 2022
Messages
114

Users who are viewing this thread

Top Bottom