views:

57

answers:

2

This appears to be .NET framework code. ByteImage = System.IO.File.ReadAllBytes("C:\my folder\my file")

Since I am not using .NET, is there equivalent code in VBA (Access 2007) that will do the same thing?

A: 

Perhaps:

''Reference: Microsoft ActiveX Data Objects x.x Library
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
mstream.LoadFromFile "c:\docs\image.jpg" 'FileNameToLoadWithFullPath

You can easily add this to a recordset like so:

rs.AddNew
rs.Fields("ImageCol").Value = mstream.Read
rs.Update
Remou
Where's the declaration for the variablve mstream?
David-W-Fenton
This is a snippet, note `New ADODB.Stream`
Remou
I think it's inadvisable to post snippets of code without their variable declarations. Even rs needs to have its declaration, since it could be either of two types of recordset, ADO or DAO.
David-W-Fenton
I do not know what type of recordset the OP wishes to use, either is equally suitable in this case and the method noted is exactly the same for both. I only suspect a recordset at all from previous posts, it is not mentioned in the question. Therefore, to declare a type in this case would be to suggest that that type should be used, when that is not the case.
Remou
Thanks for the suggestions guys! I could not get the mstream to work, probably because I don't have the correct references, but the "Open X for binary access read....." solved the problem. Many Thanks to both of you for your responses!!
jrc
References are a different thing altogether :) I have added a note.
Remou
I would think that if you're using an ADOX object, an ADO recordset would be the nicest way to interact with it. But it might not make any difference.
David-W-Fenton
A: 
  Dim ByteImage() As Byte

  Open "C:\my folder\my file" For Binary Access Read As #1

  ReDim ByteImage(1 To LOF(1))
  Get #1, , ByteImage

  Close #1
GSerg