Hi, I am not an access expert and so hope the solution to this may be fairly straight forward.
I am trying to return a value gained from a function into a specific field on a form. I have a few fields in which i would like to do this so rather than creating multiple codes referencing individual fileds I am hoping that I could pass this info to the function and then have the function pass the result back. The below code is predominantly from microsoft where I am able to browse to a file and return its path & name.
I have called the below function with...
Call Attachments(Form, Form.PassField)
The following function retrieves the path and file name ok but when requested to return that info ('**** section) into the form and control above i get the error...
Run-time error '2465':
Application-defined or object-defined error
Function Attachments(frm As Form, strFieldName As Control)
'Requires reference to Microsoft Office 10.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
'Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
'Set the title of the dialog box.
.Title = "Please select a file"
'Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Access Databases", "*.JPG"
.Filters.Add "Access Databases", "*.BMP"
.Filters.Add "Access Databases", "*.PDF"
.Filters.Add "All Files", "*.*"
'Show the dialog box. If the .Show method returns True, the
'user picked at least one file. If the .Show method returns
'False, the user clicked Cancel.
If .Show = True Then
'Loop through each file selected and add it to our list box.
For Each varFile In .SelectedItems
'****
frm.strFieldName.Name = varFile
'****
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Function
Any assistance would be greatly appreciated - thanks Vin
I am trying to return a value gained from a function into a specific field on a form. I have a few fields in which i would like to do this so rather than creating multiple codes referencing individual fileds I am hoping that I could pass this info to the function and then have the function pass the result back. The below code is predominantly from microsoft where I am able to browse to a file and return its path & name.
I have called the below function with...
Call Attachments(Form, Form.PassField)
The following function retrieves the path and file name ok but when requested to return that info ('**** section) into the form and control above i get the error...
Run-time error '2465':
Application-defined or object-defined error
Function Attachments(frm As Form, strFieldName As Control)
'Requires reference to Microsoft Office 10.0 Object Library.
Dim fDialog As Office.FileDialog
Dim varFile As Variant
'Set up the File Dialog.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
'Set the title of the dialog box.
.Title = "Please select a file"
'Clear out the current filters, and add our own.
.Filters.Clear
.Filters.Add "Access Databases", "*.JPG"
.Filters.Add "Access Databases", "*.BMP"
.Filters.Add "Access Databases", "*.PDF"
.Filters.Add "All Files", "*.*"
'Show the dialog box. If the .Show method returns True, the
'user picked at least one file. If the .Show method returns
'False, the user clicked Cancel.
If .Show = True Then
'Loop through each file selected and add it to our list box.
For Each varFile In .SelectedItems
'****
frm.strFieldName.Name = varFile
'****
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Function
Any assistance would be greatly appreciated - thanks Vin