Results 1 to 8 of 8

Thread: Saving pictures from MS Access to files using VBscript

  1. #1
    Join Date
    Dec 2004
    Posts
    159
    Rep Power
    0

    Default Saving pictures from MS Access to files using VBscript

    I am having a problem trying to saving some pictures that are stored in an MS Access database to files individually using vbscript can anyone help me on how I can achieve this.

    My Code

    DB_Conn.open(DB_ConnStng)

    if DB_Conn.State = adStateOpen then
    oRecordset.Open sSQL, DB_Conn, adOpenForwardOnly, adLockReadOnly

    if oRecordset.State = adStateOpen then
    count = 0
    Do While Not oRecordset.EOF
    oFileStream.Open
    count = count + 1

    oFileStream.Write oRecordset.Fields(strFieldName).Value
    strImagePath = strFolderPath & "\Image" & CStr(count) & ".bmp"
    oFileStream.SaveToFile strImagePath, adSaveCreateOverWrite

    oRecordset.MoveNext
    oFileStream.Close
    Loop
    oRecordset.Close
    end if
    end if
    The problem I am having is that the picture is not showing in the file and even thou it has the picture file size.

    FYI: The field type is OLE Object.
    Last edited by samuelmitch; Dec 5, 2007 at 05:20 AM. Reason: remove unecessary code
    live good today cause u will never know wat will happen 2marrow and it was never promised to no man either

  2. #2
    Join Date
    Aug 2002
    Posts
    6,223
    Rep Power
    0

    Default

    Perhaps the picture is not stored in the database as BMP, but as JPG or other format?

    I would also suggest you add the following code:
    oRecordset.MoveLast
    oRecordset.MoveFirst
    if oRecordset.RecordCount = 0 then Exit Sub
    before moving through the records.
    .
    PC - Ubuntu 15.04 64bit Desktop
    HP Pav G60-236US 3GB RAM Laptop, Ubuntu 15.04 64bit and Win7 Home

    "So Daddy, how come you telling me stealing not right when YOU copying DVDs? How come? How Come?"


    RIP Ramesh ...

  3. #3
    Join Date
    Dec 2004
    Posts
    159
    Rep Power
    0

    Default

    I am trying it with a test database which contain only bmp picture files but it just dont work.

    @Ramesh thanks for the advice, I was wondering how i was getting no record count value when I tested the script.
    live good today cause u will never know wat will happen 2marrow and it was never promised to no man either

  4. #4
    Join Date
    Dec 2004
    Posts
    159
    Rep Power
    0

    Default

    I still havent gotten how to retrieve a picture/image from ms access database and save it as a file using vbscript. can anyone help!
    live good today cause u will never know wat will happen 2marrow and it was never promised to no man either

  5. #5
    Join Date
    Aug 2002
    Posts
    6,223
    Rep Power
    0

    Default

    .
    PC - Ubuntu 15.04 64bit Desktop
    HP Pav G60-236US 3GB RAM Laptop, Ubuntu 15.04 64bit and Win7 Home

    "So Daddy, how come you telling me stealing not right when YOU copying DVDs? How come? How Come?"


    RIP Ramesh ...

  6. #6
    Join Date
    Dec 2004
    Posts
    159
    Rep Power
    0

    Default

    Quote Originally Posted by ramesh View Post
    this does not really help but thanks anyway
    live good today cause u will never know wat will happen 2marrow and it was never promised to no man either

  7. #7
    Join Date
    Dec 2004
    Posts
    159
    Rep Power
    0

    Default

    What format is bmp image as ole object in MS Access stored as, is it binary?

    if I added like a bmp image to it , do i have to write it to ole object as a binary format?

    Can I read the bmp image stored as ole object in MS Access as binary?
    live good today cause u will never know wat will happen 2marrow and it was never promised to no man either

  8. #8
    Join Date
    Dec 2004
    Posts
    159
    Rep Power
    0

    Default

    I could not get the code to convert ole object in MS Access to to its file (image/picture) to work in vbscript so I used this code sample app in Access from this link here
    live good today cause u will never know wat will happen 2marrow and it was never promised to no man either

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •