Solved Add pdf file as attachment in Form (1 Viewer)

Jimal

Member
Local time
Today, 12:52
Joined
Sep 29, 2020
Messages
60
dear all

I am in need to attach a Note file(pdf) or say a guideline document for my project in the MAIN FORM .

the attachment is not a part of any table or query..i want it a kind of embedded file which opens upon clicking
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:22
Joined
May 7, 2009
Messages
19,233
you can have a button and on it's click event open the file:

private sub button_click()
application.followhyperlink currentproject.path & "\thepdf.pdf"
end sub
 

Jimal

Member
Local time
Today, 12:52
Joined
Sep 29, 2020
Messages
60
thank u @arnelgp
but it adds a baggage that whenever I share the project file, this guideline file also to accompany..
will there be a alternate method to embedd the pdf/excel/wtever type within the Accdb file itself
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:22
Joined
May 7, 2009
Messages
19,233
you create a table with attachment field.
you add the pdf to the attachment field.
you then extract it and show.

see the table1 on the sample.
see Module1 that extract the attachment.
see the code-behind the Click event of the button.
 

Attachments

  • attachedPDF.zip
    773.1 KB · Views: 118

Jimal

Member
Local time
Today, 12:52
Joined
Sep 29, 2020
Messages
60
@arnelgp ..u r a geek sir..
it works well..thanks..

it might be too much to ask you help, but for a beginner level at coding im in need to ask..pardon me.
I tried modifying the code.. if I need to embed excel file and needless to say I failed miserably..
also if I have multiple files to embed, will the same procedure works ???
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:22
Joined
May 7, 2009
Messages
19,233
You only need to add 1 attachment on that 1 record.
so just replace the pdf file attachment with your excel file.

on Module1, change my.pdf to any name with excel file extension (.xlsx or .xls whichever you have).
on Form1 code, change also my.pdf that matched the name you made in Module1.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:22
Joined
May 7, 2009
Messages
19,233
I change the structure and rename tblPDF to tblAttachment.
see the table in design view.
i also change the code of the module so you pass the ID of the Record
you want to get the attachment.
you also pass the path+filename to create.

see the code of Module1 and the code on Form1.

be warned that adding attachment to the table will
cause for your db to bloat.
 

Attachments

  • attachedPDF.zip
    866 KB · Views: 102

Jimal

Member
Local time
Today, 12:52
Joined
Sep 29, 2020
Messages
60
thank u @arnelgp
done
I have a curious doubt - I just thought to extract or save the attachment in a new folder hence modified the code
strExcel = CurrentProject.Path & "\newfolder\thisExcel.xlsx"

but while executing it showed up a fancy error - ofcourse which I am not aware - hope it might enthral u (ref to the help window attached)
 

Attachments

  • error.JPG
    error.JPG
    18.4 KB · Views: 84
  • err help.JPG
    err help.JPG
    18.6 KB · Views: 85

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:22
Joined
May 7, 2009
Messages
19,233
You need to Create the folder if it does not exists.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:22
Joined
May 7, 2009
Messages
19,233
ok, goodluck :)
 

Users who are viewing this thread

Top Bottom