Answered by:
Show the OLE Object that saved to a SQL table in Access Form

Question
-
I attach the personnel's photo and documents (including SSO Card scan and etc.) to my form by this code. My back end database is SQL and the "MCScan" field data type is "varbinary(max).
Now I want to after clicking a button on my form I can see the attached file in form. (in an image box or etc.).I tried several ways but they were unsuccessful.
Private Sub cmdAttachMCScan_Click() Dim rs As ADODB.Recordset Dim fd As FileDialog Set rs = New ADODB.Recordset Set fd = Application.FileDialog(msoFileDialogFilePicker) rs.Open "SELECT * FROM tblEmployee WHERE EmployeeID= " & Me.EmployeeID.Value, CurrentProject.Connection, adOpeDynamic, adLockOptimistic Set streamobj = New ADODB.Stream streamobj.Type = adTypeBinary streamobj.Open 'Display the file dialouge to get the path of the file Dim strPath As String fd.AllowMultiSelect = False fd.Show strPath = fd.SelectedItems(1) streamobj.LoadFromFile strPath rs.Fields("MCScan").Value = streamobj.Read rs.Update Set fd = Nothing MsgBox ("The file attached successfully.") End Sub
Karim Vaziri Regards,
Friday, May 11, 2018 3:19 PM
Answers
-
Hi Karim,
Have you tried using a Bound Image Control? If that doesn't work, you could try using VBA similar to the following:
Me.ImageControlName.PictureData = Me.MCScan
Hope it helps...
PS. What version of MS Access are you using? The above approach will only work with 2010 and above.
- Marked as answer by kvaziri Friday, May 11, 2018 4:28 PM
Friday, May 11, 2018 3:29 PM
All replies
-
Hi Karim,
Have you tried using a Bound Image Control? If that doesn't work, you could try using VBA similar to the following:
Me.ImageControlName.PictureData = Me.MCScan
Hope it helps...
PS. What version of MS Access are you using? The above approach will only work with 2010 and above.
- Marked as answer by kvaziri Friday, May 11, 2018 4:28 PM
Friday, May 11, 2018 3:29 PM -
Dear Dbguy,
The Bound image control didn't worked. I tried your offer as follow:
Private Sub cmdShowMC_Click() ' Show the preview of scanned file Me.imgShowMC.Visible = True Me.imgShowMC.PictureData = Me.MCScan End Sub
Karim Vaziri Regards,
Friday, May 11, 2018 4:28 PM -
Hi Karim,
Glad to hear you got it to work. Good luck with your project.
Friday, May 11, 2018 4:36 PM