We help IT Professionals succeed at work.

Display Picture from MS Access Control to VB PictureBox

Medium Priority
925 Views
Last Modified: 2012-06-22
Hello..
I have a problem displaying image in picture box.
The image source  is from MSAccess control image.

Set Picture1.Picture = xImage.Picture   ' This is error!!!!!

Anybody know how to set this picturebox ?
Thanks
'here is a part of my code
'oCtls is Access.Controls
'oCtl is Access.Control
 
        Dim xImage As Access.Image
        For Each oCtl In oCtls
            If TypeOf oCtl Is Access.Image Then
                      Set xImage = oCtl
                      Set Picture1.Picture = xImage.Picture   ' This is error!!!!!
                    End If
        Next oCtl
        Set oCtl = Nothing

Open in new window

Comment
Watch Question

Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Try using the PictureData property:

Set Picture1.PictureData = xImage.PictureData

How are you actually doing this? Are you automating Access from VB, or are you using a VB control in Access?

Author

Commented:
I can't find PictureData property in PictureBox control.
Here is my code...
Private Sub GetImageInForm(ByVal strFormName As String)
 
        Dim oAccess As Access.Application
        Dim oForm As Access.Form
        Dim oCtls As Access.Controls
        Dim oCtl As Access.Control
        Dim sDBPath As String 'path to Northwind.mdb
        Dim sForm As String 'name of form to show
        Dim xImage As Access.Image
        
        sForm = strFormName
        Set oAccess = New Access.Application
        oAccess.Visible = False
        sDBPath = oAccess.SysCmd(Action:=Access.AcSysCmdAction.acSysCmdAccessDir)
        sDBPath = "C:\Program Files\Microsoft Office\Office12\Samples\Northwind.mdb"
        ' Open Northwind.mdb in shared mode:
        oAccess.OpenCurrentDatabase filepath:=sDBPath, Exclusive:=False
        'Close all openned Form
        For Each oForm In oAccess.Forms
            oAccess.DoCmd.Close ObjectType:=Access.AcObjectType.acForm, _
                ObjectName:=oForm.Name, _
                Save:=Access.AcCloseSave.acSaveNo
        Next
 
        Set oForm = Nothing
        ' Select the form name in the database window and give focus
        ' to the database window:
        oAccess.DoCmd.SelectObject ObjectType:=Access.AcObjectType.acForm, _
            ObjectName:=sForm, InDatabaseWindow:=True
        ' Show the form:
        oAccess.DoCmd.OpenForm FormName:=sForm, View:=Access.AcFormView.acNormal
        Set oForm = oAccess.Forms(sForm)
        Set oCtls = oForm.Controls
        
        For Each oCtl In oCtls
            If TypeOf oCtl Is Access.Image Then
                      Set xImage = oCtl
                      'Trying to display image
                      Set Picture1.Picture = xImage.Picture   ' This is error!!!!!
                      
                    End If
        Next oCtl
        Set oCtl = Nothing
 
        ' Hide the Database Window:
        oAccess.DoCmd.SelectObject ObjectType:=Access.AcObjectType.acForm, _
            ObjectName:=sForm, InDatabaseWindow:=True
        oAccess.RunCommand Command:=Access.AcCommand.acCmdWindowHide
        ' Release Controls and Form objects:
        Set oCtls = Nothing
        Set oForm = Nothing
        ' Release Application object and allow Access to be closed by user:
        If Not oAccess.UserControl Then oAccess.UserControl = True
        Set oAccess = Nothing
        Exit Sub
ErrorCleanup:
        ' Try to quit Access due to an unexpected error:
        On Error Resume Next
        Set oCtl = Nothing
        Set oCtls = Nothing
        Set oForm = Nothing
        Set oAccess = Nothing
        Exit Sub
ErrorHandler:
        MsgBox Err.Number & ": " & Err.Description, _
            MsgBoxStyle.MsgBoxSetForeground, "Error Handler"
        Resume ErrorCleanup
End Sub

Open in new window

Scott McDaniel (EE MVE )Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Did you try:

Set Picture1.Picture = xImage.PictureData

Author

Commented:
I have tried that
Runt-time error '424':
Object Required
Infotrakker Software
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
Sorry ... try it without the Set:

Picture1.Picture = xImage.PictureData

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Stil error...
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.