Reputation: 508
In MS Access I'd like to be able to search for an image, or images, on the system and then save them into OLE fields in tables that are linked to an SQL server.
Having a preview in the form would be ideal as well.
This seems like a simple task but honestly I've given up after hours of searching. And as I'm storing the images as Varbinary(MAX) in an SQL database, no I don't want to just store a link to the images.
Upvotes: 0
Views: 1147
Reputation: 11
After setting an image field, I attached this to a button:
Private Sub CommandOpenPicture_Click()
Dim strFilter As String
Dim strInputFileName As String
strFilter = ahtAddFilterItem(strFilter, "JPEG Files (*.jpg, *.jpeg)", "*.jpg;*.jpeg")
strFilter = ahtAddFilterItem(strFilter, "bmp Files (*.bmp)", "*.bmp")
strFilter = ahtAddFilterItem(strFilter, "all Files (*.*)", "*.*")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, _
OpenFile:=True, _
DialogTitle:="Choose an image file...", _
Flags:=ahtOFN_HIDEREADONLY)
If Len(strInputFileName) > 0 Then
' Do something with the selected file
imgDamPic.Picture = strInputFileName
Me.DamsPhoto.Value = imgDamPic.Picture
file_path.Value = strInputFileName
'Put SQL Insert Statement or DAO here
Else
'No file chosen, or user canceled
End If
End Sub
Upvotes: 1