MartyConnelly
martyconnelly at shaw.ca
Fri May 20 00:23:28 CDT 2005
I think you will have to dump your stream to a temp disk file first via stm.savetofile, the image picture control in Access only accepts a file as input unless it is Ole Wrapped in recordset field. something like this code to dump to file . It is irrelevant whether stream is xml or jpeg, but you may have to fiddle with Charset name which is registry defined. Sub ReadUTF8SaveFileInUTF16test() Dim stm As ADODB.stream Dim strPath As String Dim strData As String strPath = GetPath(CurrentDb.Name) Set stm = New ADODB.stream stm.Open stm.Charset = "UTF-8" stm.Position = 0 stm.Type = adTypeText 'stm.LoadFromFile strPath & "encUTF8.xml" stm.LoadFromFile "C:\XML\XM8_UTF_vb.xml" ' if you just try and dump out stream ' without reading and writing you get double BOM file marker 'check with hex editor stm.Position = 0 strData = stm.ReadText() Debug.Print strData stm.Position = 0 stm.Charset = "Unicode" ' "Unicode" '"ascii" '"Big5" '"hebrew" stm.WriteText (strData) stm.SaveToFile strPath & "test16.xml", adSaveCreateOverWrite stm.Close Set stm = Nothing End Sub Arthur Fuller wrote: > Following is the code that I'm using in the attempt to allow the user > to browse to select an image file, read the image and then store it > into a column in SQL (not Access) defined as Image data type. The code > executes fine, the debug messages post the correct file sizes and so > on, but the image does not appear on the Access form. > > New eyes often help, so I'm asking for new eyes.... > > <code> > 'form declarations code: > Option Compare Database > Option Explicit > 'declarations > Dim cn As ADODB.Connection > Dim rs As ADODB.Recordset > Dim mStream As ADODB.Stream > 'Revise this constant to suit the production or development environment. > 'This constant is produced by running the following command in the > debug window of Access 2003. > '? currentproject.Connection > 'To reproduce another version that may differ, run the application and > then re-run the above command. > Const conCNN = "Provider=Microsoft.Access.OLEDB.10.0;Persist Security > Info=False;Data Source=rock;" & _ > "User ID=sa;Password=xxxxx;Initial Catalog=TallGirl;Data > Provider=SQLOLEDB.1" > > 'this code is tied to a button on the form that should display the > table data and image if any: > Private Sub PictureImport_cmb_Click() > Dim strFileName As String > Dim strPK As String > Dim strSQL As String > With Me > strFileName = .PictureFileName > strPK = .StyleCode > strSQL = "Select * from tblStyle WHERE StyleCode = " & Chr(39) > + strPK + Chr(39) > Debug.Print strSQL > > Set cn = New ADODB.Connection > cn.Open conCNN > Set rs = New ADODB.Recordset > rs.Open strSQL, cn, adOpenKeyset, adLockOptimistic > > If rs.EOF Then > Debug.Print "No record found for StyleCode " + strPK > Return > Else > Debug.Print rs.RecordCount & " row(s) found." > End If > Set mStream = New ADODB.Stream > mStream.Type = adTypeBinary > mStream.Open > mStream.LoadFromFile .PictureFileName > Debug.Print "Size of Picture column before update = " & > Len(rs.Fields("Picture")) > Debug.Print "Size of mStream after read = " & mStream.Size > rs.Fields("Picture").Value = mStream.Read > rs.Update > Debug.Print "Size of Picture column after update = " & > Len(rs.Fields("Picture")) > Debug.Print "Size of Fields(Picture) mStream after read = " & > mStream.Size > rs.Close > cn.Close > End With > Me.Refresh > Debug.Print "Length of Picture Column now: " & Len(Me.Picture) > End Sub > </code> > > TIA, > Arthur > >> > > -- Marty Connelly Victoria, B.C. Canada