is there equivalent code in VBA Access 2007?

*爱你&永不变心* 提交于 2019-12-11 14:53:31

问题


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?


回答1:


  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



回答2:


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


来源:https://stackoverflow.com/questions/3363864/is-there-equivalent-code-in-vba-access-2007

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!