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

How do I use code to browse for an OLE object in a form?

Status
Not open for further replies.
Jun 16, 2006
1
US
I have a database that stores pictures of the people in it. There is an OLE field in the table, and on the associated form. But...In order to insert a photo, the user has to do the following steps:

1. Right-Click on the OLE Field Control
2. Select Insert Object
3. Click create from file
4. Browse for the picture
5. Click Open

That's five steps, and the first is the dreaded 'novices don't understand it' Right-click. Plus they can accidentally click 'create new', 'link to file' or god only knows what else. Since the average user has a three step limit for any given procedure, I'd like to insert an "Add a Photo" button under the OLE field control. I'm relatively sure that this is done with an fso or shell function of some sort, but that's about my limit of knowledge. I'd like the button to bring up the file browser, and skip the first 4 steps noted above. Most users can manage to click a button and locate the correct file. I'm sure this can be done, since the same function exists on many, many 'personals' type websites.
 
got this from MS website, it's a start...

Option Compare Database
Option Explicit

Private Sub cmdFileDialog_Click()

' This requires a reference to the Microsoft Office 11.0 Object Library.

Dim fDialog As Office.FileDialog
Dim varFile As Variant

' Clear the list box contents.
Me.FileList.RowSource = ""

' Set up the File dialog box.
Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
With fDialog
' Allow the user to make multiple selections in the dialog box.
.AllowMultiSelect = True

' Set the title of the dialog box.
.Title = "Select One or More Files"

' Clear out the current filters, and then add your own.
.Filters.Clear
.Filters.Add "Access Databases", "*.MDB"
.Filters.Add "Access Projects", "*.ADP"
.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 that is selected and then add it to the list box.
For Each varFile In .SelectedItems
Me.FileList.AddItem varFile
Next
Else
MsgBox "You clicked Cancel in the file dialog box."
End If
End With
End Sub
 
How are ya StephenBaer . . .

Using OLE to store your graphics will seriously bloat your DB. Have a look here for what to do: How to Display Images in a Form or in a Report Without Storing the Images

Either way you decide, have a look at the [blue]Common Dialog[/blue] activeX control: Using the Common Dialog Control

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top