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

Need user to insert different picture for each record.

Status
Not open for further replies.
Sep 10, 2002
150
US

Hi. I have an inventory database, and I would like to create a button to import a small .jpg or .gif into the record. Thusly, whenever the record is called up, there is the visual record of the item. How can I do this? Thanx!
 
Put this code in a module and use the BrowseForFile function to get the path to the pictures. (Maybe Linked to a 'Browse...' button)

You can just have the picture field as a text field with the path to the pictures stored in it. Then, on your forms in the OnCurrent event, have an Image Control updated with it's .Picture property set to this text value from the field.

If you need any more help, let me know.
Code:
[COLOR=blue]
'-----------------------------------------------------------------------------
Private Type OPENFILENAME
  lStructSize As Long
  hWndOwner As Long
  hInstance As Long
  lpstrFilter As String
  lpstrCustomFilter As String
  nMaxCustFilter 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
  lCustData As Long
  lpfnHook As Long
  lpTemplateName As String
End Type

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Public Function BrowseForFile(Optional ByVal strFileNameIn _
                                         As String = "", Optional strDialogTitle _
                                         As String = "Name of File to Open", _
                                         Optional strFileType As String, _
                                         Optional strExtension As String)
 
    Dim lngReturn As Long
    Dim intLocNull As Integer
    Dim strTemp As String
    Dim ofnFileInfo As OPENFILENAME
    Dim strInitialDir As String
    Dim strFilename As String
    
    '-- if a file path passed in with the name,
    '-- parse it and split it off.
    
    If InStr(strFileNameIn, &quot;\&quot;) <> 0 Then
        
        strInitialDir = Left(strFileNameIn, InStrRev(strFileNameIn, &quot;\&quot;))
        strFilename = Left(Mid$(strFileNameIn, _
                                        InStrRev(strFileNameIn, &quot;\&quot;) + 1) & _
                                        String(256, 0), 256)
        
    Else
        
        strInitialDir = CurrentProject.Path
        strFilename = Left(strFileNameIn & String(256, 0), 256)
    
    End If
       
    With ofnFileInfo
        .lStructSize = Len(ofnFileInfo)
        .lpstrFile = strFilename
        .lpstrFileTitle = String(256, 0)
        .lpstrInitialDir = strInitialDir
        .hWndOwner = Application.hWndAccessApp
        If strFileType <> &quot;&quot; And strExtension <> &quot;&quot; Then
            .lpstrFilter = strFileType & &quot; &quot; & &quot;(*.&quot; & strExtension & &quot;)&quot; & Chr(0) & _
                                                    &quot;*.&quot; & UCase(strExtension) & Chr(0)
        Else
            .lpstrFilter = &quot;All Files (*.*)&quot; & Chr(0) & &quot;*.*&quot; & Chr(0)
        End If
        .nFilterIndex = 1
        .nMaxFile = Len(strFilename)
        .nMaxFileTitle = ofnFileInfo.nMaxFile
        .lpstrTitle = strDialogTitle
        '.flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly Or _
                            cdlOFNNoChangeDir
        .hInstance = 0
        .lpstrCustomFilter = String(255, 0)
        .nMaxCustFilter = 255
        .lpfnHook = 0
    End With
    
    lngReturn = GetOpenFileName(ofnFileInfo)
    
    If lngReturn = 0 Then
       strTemp = &quot;&quot;
    Else
       
       '-- Trim off any null string
       strTemp = Trim(ofnFileInfo.lpstrFile)
       intLocNull = InStr(strTemp, Chr(0))
       
       If intLocNull Then
          strTemp = Left(strTemp, intLocNull - 1)
       End If
 
    End If

    BrowseForFile = strTemp
    
End Function
'-----------------------------------------------------------------------------
[/color]

Dean :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top