Command button to insert picture

manojsikar1

Registered User.
Local time
Today, 09:10
Joined
Nov 11, 2012
Messages
15
hello evrybody,
in form i want to put a command where we can browse a picture and insert it...how to do ...

plz help
 
Use a command button and then place code to display the file browser to select the picture and return the filepath. Store this filepath in a field for the forms underlying table. Then add some code to the forms OnCurrent event to 'load' the picture.

Code to get file
Code:
Private Sub cmdGetImage_Click()
' Requires reference to Microsoft Office 11.0 Object Library.

   Dim fDialog As Office.FileDialog
   Dim varFile As Variant

   ' Set up the File Dialog.
   Set fDialog = Application.FileDialog(msoFileDialogFilePicker)

   With fDialog
      ' Allow user to make multiple selections in dialog box
      '.AllowMultiSelect = True
 
      ' Set the title of the dialog box.
      .Title = "Please select your picture"
        
      ' Clear out the current filters, and add our own.
      .Filters.Clear
      .Filters.Add "Pictures", "*.jpg; *.bmp; *.dib; *.gif*"

      ' 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. Even if MultiSelect is false, use this to get the single file selected
         For Each varFile In .SelectedItems
            Me.ControlName.Picture = varFile
            Me.FieldName = varFile
         Next

      Else
         MsgBox "You clicked Cancel in the file dialog box."
      End If
   End With
End Sub
Code to load image

Code:
Private Sub Form_Current()
Me.ImageControl.Picture = Me.ImageFieldName
End Sub

You can not use Continuous Forms for displaying images as each image will be the same as the current record.
 
I am using office 2003....will vb command work in it...
 
So long as you set a reference to Microsoft Office xx Object Library (xx being the version on your machine 10?)
 
Isskint


Hi,

I've designed a basic database for my small gallery to keep record of the artwork we sell. However I need a command button to insert an image for each record to be displayed on the forms. My knowledge on Microsoft Access is rather basic so the above post with the code is more than likely what I need but I have no idea how to use it or what to do with it!

:banghead:

I've taken some screenshots of my DB to show what I'm working with. If you could give me some step by step instructions (as idiot proof as possible :( Screen shots would be great! :o) that would be so helpful!

DB 1.png

DB 2.png

DB 3.png
 
In my form i cannot select multiple images and the next/previous
button not working,also want the path to show in the above text field to copy the image name and give entry in the sub form.i have my db attached here.can any one help me with this,thanks.
 

Attachments

Last edited:

Users who are viewing this thread

Back
Top Bottom