Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Location
    ny, ny
    Posts
    224

    Unanswered: inserting a picture

    I have a field on a form in which i want to insert a picture. It has been set to OLE object. Presently to insert a picture I have to click on insert and browse for object and select it
    How do I set it so that double clicking on the field itself will take me to the browse window

    thank you

  2. #2
    Join Date
    Nov 2003
    Posts
    1,487
    First...you need a means to open a file dialog box. The code below allows you do do just that. It allows you to open either a Open or Save dialog box. Just place it into a main database code module:


    Code:
    Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Boolean
    Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Boolean
    
    Type MSA_OPENFILENAME
    ' Filter string used for the File Open dialog filters.
    ' Use MSA_CreateFilterString() to create this.
    ' Default = All Files, *.*
    	strFilter As String
    ' Initial Filter to display.
    ' Default = 1.
    	lngFilterIndex As Long
    ' Initial directory for the dialog to open in.
    ' Default = Current working directory.
    	strInitialDir As String
    ' Initial file name to populate the dialog with.
    ' Default = "".
    	strInitialFile As String
    	strDialogTitle As String
    ' Default extension to append to file if user didn't specify one.
    ' Default = System Values (Open File, Save File).
    	strDefaultExtension As String
    ' Flags (see constant list) to be used.
    ' Default = no flags.
    	lngFlags As Long
    ' Full path of file picked.  On OpenFile, if the user picks a
    ' nonexistent file, only the text in the "File Name" box is returned.
    	strFullPathReturned As String
    ' File name of file picked.
    	strFileNameReturned As String
    ' Offset in full path (strFullPathReturned) where the file name
    ' (strFileNameReturned) begins.
    	intFileOffset As Integer
    ' Offset in full path (strFullPathReturned) where the file extension begins.
    	intFileExtension As Integer
    End Type
    
    Const ALLFILES = "All Files"
    
    Type OPENFILENAME
    	lStructSize As Long
    	hWndOwner As Long
    	hInstance As Long
    	lpstrFilter As String
    	lpstrCustomFilter As Long
    	nMaxCustrFilter As Long
    	NFilterIndex As Long
    	lpstrFile As String
    	nMaxFile As Long
    	lpstrFileTitle As String
    	nMaxFileTitle As Long
    	lpstrInitialDir As String
    	lpstrTitle As String
    	Flags As Long
    	nFileOffset As Integer
    	nFileExtension As Integer
    	lpstrDefExt As String
    	lCustrData As Long
    	lpfnHook As Long
    	lpTemplateName As Long
    End Type
    
    Const OFN_ALLOWMULTISELECT = &H200
    Const OFN_CREATEPROMPT = &H2000
    Const OFN_EXPLORER = &H80000
    Const OFN_FILEMUSTEXIST = &H1000
    Const OFN_HIDEREADONLY = &H4
    Const OFN_NOCHANGEDIR = &H8
    Const OFN_NODEREFERENCELINKS = &H100000
    Const OFN_NONETWORKBUTTON = &H20000
    Const OFN_NOREADONLYRETURN = &H8000
    Const OFN_NOVALIDATE = &H100
    Const OFN_OVERWRITEPROMPT = &H2
    Const OFN_PATHMUSTEXIST = &H800
    Const OFN_READONLY = &H1
    Const OFN_SHOWHELP = &H10
    
    
    'Procedure BrowseForFile (Dialog Box)
    Public Function BrowseForFile(strSearchPath) As String
    '---------------------------------------------------------------
    ' Displays the open file dialog box for the user to locate a File.
    ' Returns the full path to the selected file.
    '---------------------------------------------------------------
    	Dim msaof As MSA_OPENFILENAME
    	
    ' Set options for the dialog box.
    	msaof.strDialogTitle = "Browse For File...."
    	If strSearchPath = "" Then msaof.strInitialDir = "C:\" Else msaof.strInitialDir = strSearchPath
    	msaof.strFilter = MSA_CreateFilterString("Graphics Files (*.bmp; *jpg; *.gif; *.wmf; *.emf; *.dib)", "*.wmf;*.bmp;*.jpg;*.gif;*.emf;*.dib", "All Files (*.*)", "*.*")
    
    ' Call the Open File dialog routine.
    	MSA_GetOpenFileName msaof
    	
    ' Return the path and file name.
    	BrowseForFile = Trim(msaof.strFullPathReturned)
    End Function
    
    
    'procedure MSA_CreateFilterString
    Function MSA_CreateFilterString(ParamArray varFilt() As Variant) As String
    '-------------------------------------------------------------------
    ' Creates a filter string from the passed in arguments.
    ' Returns "" if no args are passed in.
    ' Expects an even number of args (filter name, extension), but
    ' if an odd number is passed in, it appends *.*
    '-------------------------------------------------------------------
    	Dim strFilter As String
    	Dim intRet As Integer
    	Dim intNum As Integer
    
    	intNum = UBound(varFilt)
    	If (intNum <> -1) Then
    		For intRet = 0 To intNum
    			strFilter = strFilter & varFilt(intRet) & Chr$(0)
    		Next
    		If intNum Mod 2 = 0 Then
    			strFilter = strFilter & "*.*" & Chr$(0)
    		End If
    		
    		strFilter = strFilter & Chr$(0)
    	Else
    		strFilter = ""
    	End If
    
    	MSA_CreateFilterString = strFilter
    End Function
    'procedure MSA_GetOpenFileName
    Public Function MSA_GetOpenFileName(msaof As MSA_OPENFILENAME) As Integer
    '---------------------------------------------------------------
    ' Opens the file open dialog.
    '---------------------------------------------------------------
    	Dim of As OPENFILENAME
    	Dim intRet As Integer
    
    	MSAOF_to_OF msaof, of
    	intRet = GetOpenFileName(of)
    	If intRet Then
    		OF_to_MSAOF of, msaof
    	End If
    	MSA_GetOpenFileName = intRet
    End Function
    'procedure MSA_GetSaveFileName
    Public Function MSA_GetSaveFileName(msaof As MSA_OPENFILENAME) As Integer
    '------------------------------------------------------
    ' Opens the file save dialog.
    '------------------------------------------------------
    	Dim of As OPENFILENAME
    	Dim intRet As Integer
    
    	MSAOF_to_OF msaof, of
    	of.Flags = of.Flags Or OFN_HIDEREADONLY
    	intRet = GetSaveFileName(of)
    	If intRet Then
    		OF_to_MSAOF of, msaof
    	End If
    	MSA_GetSaveFileName = intRet
    End Function
    'procedure MSAOF_to_OF
    Private Sub MSAOF_to_OF(msaof As MSA_OPENFILENAME, of As OPENFILENAME)
    '-----------------------------------------------------------------
    ' This sub converts from the friendly MSAccess structure to the
    '  win32 structure.
    '-----------------------------------------------------------------
    	Dim strFile As String * 512
    
    	' Initialize some parts of the structure.
    	of.hWndOwner = Application.hWndAccessApp
    	of.hInstance = 0
    	of.lpstrCustomFilter = 0
    	of.nMaxCustrFilter = 0
    	of.lpfnHook = 0
    	of.lpTemplateName = 0
    	of.lCustrData = 0
    	
    	If msaof.strFilter = "" Then
    		of.lpstrFilter = MSA_CreateFilterString(ALLFILES)
    	Else
    		of.lpstrFilter = msaof.strFilter
    	End If
    	of.NFilterIndex = msaof.lngFilterIndex
    	
    	of.lpstrFile = msaof.strInitialFile _
    				& String$(512 - Len(msaof.strInitialFile), 0)
    	of.nMaxFile = 511
    
    	of.lpstrFileTitle = String$(512, 0)
    	of.nMaxFileTitle = 511
    
    	of.lpstrTitle = msaof.strDialogTitle
    
    	of.lpstrInitialDir = msaof.strInitialDir
    	
    	of.lpstrDefExt = msaof.strDefaultExtension
    
    	of.Flags = msaof.lngFlags
    	
    	of.lStructSize = Len(of)
    End Sub
    'procedure OF_to_MSAOF
    Private Sub OF_to_MSAOF(of As OPENFILENAME, msaof As MSA_OPENFILENAME)
    '---------------------------------------------------------------------
    ' This sub converts from the win32 structure to the friendly MSAccess
    ' structure.
    '---------------------------------------------------------------------
    	msaof.strFullPathReturned = Left$(of.lpstrFile, _
    		InStr(of.lpstrFile, Chr$(0)))
    	msaof.strFileNameReturned = of.lpstrFileTitle
    	msaof.intFileOffset = of.nFileOffset
    	msaof.intFileExtension = of.nFileExtension
    End Sub
    The function you want to use is called the BrowseForFile function
    and it is used in this fashion. Place the code into the Dbl Click event of your Control. I have already set the filters for the dialog box to display picture files:


    Code:
    	Dim Strg As String
    	If Me![myOleObjectControlName].Picture <> "" Then Strg = Me![myOleObjectControlName].Picture
    	Strg = BrowseForFile(Strg)
    	If Strg = "" Then Exit Sub
    	Me![myOleObjectControlName].Picture = Strg
    Hope this helps...


  3. #3
    Join Date
    Apr 2006
    Posts
    1

    what am i doing wrong?

    i used the code provided, however i get this error msg when i try to use the browseforfile code...

    Run-time error '438'
    Object doesnt support this property or method

    then in the debugger the red part of this line is highlighted:

    If Me![OLEBound68].Picture <> "" Then Strg = Me![OLEBound68].Picture

    can anyone help me with this? I am very new to access and dont understand why its not working.

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    The sample code that was provided is shown for use with the Image Control, not a Bound Object Frame Control which does not support the Picture property.

    Use the Image Control instead of the Bound Object Frame Control.

    .
    Environment:
    Self Taught In ALL Environments.....And It Shows!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •