locked
Trying to find how to at RunTime assign a Picture or image to an unbound Object Frame on a SubForm. RRS feed

  • Question

  • Trying to find how to at RunTime assign a Picture or image to an unbound Object Frame on a SubForm.

    In an Access .accdb file. Win7 Ultimate   Office 2013 Access 2013 both 64bit. VBA 7.1

    Also how to store the various picture or images with the Access .accdb file.  Seems best way is to have a table with a OLE object field.

    In design view of form I can assign an image I created in Microsoft Paint (BMP file).

    So it seems I could assign any image I can get in Microsoft Paint to the Unbound Object Frame in a SubForm.

    Looking for the syntax to assign an image code picks to the SubForm code also picks.

    Thanks,

    Mark


    Mark J

    Tuesday, March 1, 2016 10:39 AM

Answers

  • Hi, PuzzledByWord

    >>1. Yes only bmp file work with unbound object frame.

    >>2. i have check on my side if folder contains spaces in name then also it is working fine.

    The other thing i want to tell you that if you want to upload bmp, jpeg, png, gif then you can work with "Image Control". if you want to work with images then image control is a better option instead of unbound object frame.

    also you can select image from open file dialog.

    i have posted a code below you can try.

        

    Private Sub Command4_Click()
    Const msoFileDialogFilePicker As Long = 3
    Dim objDialog As Object

    Set objDialog = Application.FileDialog(msoFileDialogFilePicker)

    With objDialog
        .AllowMultiSelect = False
            .Filters.Clear
            .Filters.Add "Images", "*.gif; *.jpg; *.jpeg; *.png; *.bmp"

       If .Show = -1 Then
                For Each filename In .SelectedItems
                  Me.pic.Picture = filename
                Next
            Else
                MsgBox "No image selected."
            End If
        End With

    End Sub

    Regards

    Deepak

    Sunday, March 6, 2016 10:54 AM
  • Why not use an Image control and as its ControlSource property reference a text column in the table in which the path to the image file is stored?  Bear in mind that a very large image file will take a little time to load at runtime.  Modern high resolution digital cameras create very large files for instance, so it is best to reference a reduced resolution version of such files to enhance performance.  Any image management software, e.g. Picasa, will enable you easily to create a smaller version of the file for use by the database.

    Ken Sheridan, Stafford, England

    Sunday, March 6, 2016 6:05 PM

All replies

  • Hi, PuzzledByWord

    With the following vba code you can set image at run time.

    Private Sub Command24_Click()

     On Error GoTo Error_Command24_Click

       With Me![ubo]

          .Enabled = True

          .Locked = False

          ' Specify what kind of object can appear in the field.

          .OLETypeAllowed = acOLELinked

        

          ' Specify the file to be linked.

          ' Type the correct path name.

          .SourceDoc = "C:\Users\Administrator\Desktop\demo1.bmp"

        

          .Action = acOLECreateLink

          ' Optional size adjustment.

          .SizeMode = acOLESizeZoom

       End With

    Exit_Command24_Click:

       Exit Sub

    Error_Command24_Click:

       MsgBox CStr(Err) & " " & Err.Description

       Resume Exit_Command24_Click

    End Sub

    Yes you can save images with OLE object field.

    Regards

    Deepak

    Thursday, March 3, 2016 1:27 AM
  • Deepak,

    I have a question on this code.

    1.  Does this ONLY work for   BMP files  ?     Could NOT seem to get it to work for  JPG    or  PNG files.

    2. It did NOT seem to work when the Path to the file had a space in the folder name.  Like below.

         part of path  was    \Public\Public Pix\FileName.bmp          A SPACE BETWEEN PUBLIC and PIX.

    When I copied the file to a path without any spaces in the folder name your code worked great.

    Is there a special way to deal with a blank space in the folder name?

    Thanks

    Mark J


    Mark J

    Sunday, March 6, 2016 9:04 AM
  • Hi, PuzzledByWord

    >>1. Yes only bmp file work with unbound object frame.

    >>2. i have check on my side if folder contains spaces in name then also it is working fine.

    The other thing i want to tell you that if you want to upload bmp, jpeg, png, gif then you can work with "Image Control". if you want to work with images then image control is a better option instead of unbound object frame.

    also you can select image from open file dialog.

    i have posted a code below you can try.

        

    Private Sub Command4_Click()
    Const msoFileDialogFilePicker As Long = 3
    Dim objDialog As Object

    Set objDialog = Application.FileDialog(msoFileDialogFilePicker)

    With objDialog
        .AllowMultiSelect = False
            .Filters.Clear
            .Filters.Add "Images", "*.gif; *.jpg; *.jpeg; *.png; *.bmp"

       If .Show = -1 Then
                For Each filename In .SelectedItems
                  Me.pic.Picture = filename
                Next
            Else
                MsgBox "No image selected."
            End If
        End With

    End Sub

    Regards

    Deepak

    Sunday, March 6, 2016 10:54 AM
  • Why not use an Image control and as its ControlSource property reference a text column in the table in which the path to the image file is stored?  Bear in mind that a very large image file will take a little time to load at runtime.  Modern high resolution digital cameras create very large files for instance, so it is best to reference a reduced resolution version of such files to enhance performance.  Any image management software, e.g. Picasa, will enable you easily to create a smaller version of the file for use by the database.

    Ken Sheridan, Stafford, England

    Sunday, March 6, 2016 6:05 PM