Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting an object in a form

Status
Not open for further replies.

spurs100

Technical User
Jun 5, 2002
20
GB
Hi All,

Can anyone help?

I have a form with a field that i want to contain a pdf document, at present i have to select the field then click on Insert-Object, from there i have to browse to find the file i want to upload.

Is there anyway of having a button that when i click on it, the insert object window appears and is defaulted to create from file and points to the directory i wish.

Many thanks in advance

 
You can't really format the Insert Object Dialog, but you can call it from a button:

Private Sub cmdInsertOLE_Click()
On Error GoTo ErrHandler

' Set class name.
OLE1.Class = "AcroExch.Document"

' Specify type of object.
OLE1.OLETypeAllowed = acOLELinked

' Specify source file.
OLE1.SourceDoc = "C:\Docs\" & Dir("C:\Docs\*.pdf")

' Open the dialog.
OLE1.Action = acOLEInsertObjDlg

ExitHere:
Exit Sub
ErrHandler:
If Err = 2001 Then 'canceled
OLE1 = Null
Resume ExitHere
Else
MsgBox "Error: " & Err & " - " & Err.Description
Resume ExitHere
End If
End Sub

You can also open the Insert Object Dialog using a simple call:

RunCommand acCmdInsertObject

The most robust option would be to use a Common Dialog to retrieve the file name, which would allow you to specify a filter and init directory, then use OLE1.Action = acOLECreateLink to actually create the link.

Good Luck


VBSlammer
redinvader3walking.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top