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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Attaching Documents to Record

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
Hi

I am using the following code to attach a document (pdf, .xls, .doc) to a record but get the error

User-defined type not defined. Help please

Code:
Private Sub GetAttachment_Click()
On Error GoTo Err_GetAttachment_Click

Dim dlgAttach As FileDialog
Dim strMyFile As String
Dim varChosen As Variant

Set dlgAttach = Application.FileDialog(msoFileDialogFilePicker)

With dlgAttach
    .ButtonName = "Attach"
    .InitialView = msoFileDialogViewList
    .Title = "Choose file to attach"
    .AllowMultiSelect = False
    
    'Set up file types
    With .Filters
        .Clear
        .Add "Word Documents", "*.doc"
        .Add "Excel Spreadsheets", "*.xls"
        .Add "Adobe PDFs", "*.pdf"
        .Add "Powerpoint Presentations", "*.ppt"
    End With
    
    'Set default file type
    .FilterIndex = 1
    
    'Show Dialog Box
    
    If .Show = -1 Then
        For Each varChosen In dlgAttach.SelectedItems
            strMyFile = varChosen
        Next varChosen
    End If
End With

'Dump the chosen file name into a text control on the form
Forms!frmClientOverview!frmAddNewDocument!Location = strMyFile
Exit_GetAttachment_Click:
    Exit Sub

Err_GetAttachment_Click:
    MsgBox Err.Description
    Resume Exit_GetAttachment_Click
    
End Sub
 
Which line of code is highlighted ?
I guess this one:
Dim dlgAttach As FileDialog

If so, you should reference the Microsoft Office x.y Object Library


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes the first line

And I have reference Microsoft Office 12.0 Object Library
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top