I'm newbie . Currently I'm to trying to import the image [varbinary(max) as the data type] from sql server 2008 into the vba excel. I get "Type Mismatch" error.
Here I'm provide the code that I have
serverConn 'call the connection function
' open connection
objConnection.Open strConnectStr
Dim rs As ADODB.Recordset
Dim stm As ADODB.Stream
Set rs = New ADODB.Recordset
Set stm = New ADODB.Stream
Dim sqlquery As String
sqlquery = "SELECT [well_img] FROM well_image WHERE [img_id] = 2"
rs.Open sqlquery, objConnection, adOpenStatic, adLockOptimistic
stm.Type = adTypeBinary
stm.Open
stm.Write rs("well_img").Value 'write bytes to stream
stm.Position = 0
Sheet1.display_img.Picture = stm.Read 'this line is the problem ("Type Mismatch error")
stm.Close
rs.Close
objConnection.Close
Set stm = Nothing
Set rs = Nothing
Set objConnection = Nothing
The display_img is Image ActiveX control. Hopefully somebody can help me, I'm really need to know the answer. Thank you.