CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jan 2012
    Posts
    35

    How add OLE Pic field to Database VB5?

    Using VB5, I need to add a Picture (.bmp file) to one of my Access 3 or Access 7 databases. I assume I must use Visdata to create the Picture(OLE Object) field.

    I can't find a Type for an "OLE object".

    How can I do this?????????

    Really need help on this! Thanks

  2. #2
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Smile Re: How add OLE Pic field to Database VB5?

    Try the following way !
    Code:
    Private Sub cmdSave_Click() 
        
       'Validate the employee information 
        If ValidateData = False Then 
            Exit Sub 
        Else 
            Me.MousePointer = vbHourglass 
            'create an instance of the stream object 
            Dim smEmp As ADODB.Stream 
            Set smEmp = New ADODB.Stream 
            'set the type to binary to load the image as a binary stream 
            smEmp.Type = adTypeBinary 
            smEmp.Open 
            'Load the content of the picture into the stream object 
            smEmp.LoadFromFile fileName 
            'Check the size of the ado stream to make sure there is data 
            If smEmp.Size > 0 Then 
                'Save the Employee Information 
                rsEMP.AddNew 
                rsEMP("FirstName") = txtFName 
                rsEMP("MiddleName") = txtMName 
                rsEMP("LastName") = txtLName 
                rsEMP("SSN") = txtSSN 
                rsEMP("Notes") = txtNotes 
                'read the entire binary stream and assign it to the Photo field 
                rsEMP("Photo") = smEmp.Read 
                'Update the data 
                rsEMP.Update 
                'Clear the form 
                ClearFields 
             
                MsgBox "Employee Information Saved Successfully" 
            Else 
                MsgBox "The Employee's Photo is not valid" 
            End If 
             
            'Close and destroy the stream object reference 
            smEmp.Close 
            Set smEmp = Nothing 
         
            Me.MousePointer = vbNormal 
        End If 
    End Sub

  3. #3
    Join Date
    Jan 2012
    Posts
    35

    Re: How add OLE Pic field to Database VB5?

    Thanks for the Response!!

    When I entered the "Dim smEmp as ADODB.Stream" I got a compile error: User-defined type not defined.

    What do I need to do??

  4. #4
    Join Date
    Jan 2012
    Posts
    35

    Re: How add OLE Pic field to Database VB5?

    I set a reference to M/S ADO 2.8 lib and got the pgm to compile.

    I inserted the following code in my program and when it ran I got a System Abend:
    I have these questions: Can I use my Existing Access DB with a new field of Type binary?
    Do I need to use a different kind of database? How do I define the Type of field I will be updating? It's obvious I don't know anything about ADO.

    Thanks for your time and help!!


    '****
    Set smEmp = New ADODB.Stream
    smEmp.Type = adTypeBinary
    smEmp.Open
    smEmp.LoadFromFile ("C:\Program Files\X-DEI-LocDB\DLPicture.bmp")

    dtaLocation.Recordset.Edit ' this is my DB with a binary field named txtlocDLPic
    txtLocDLPic = smEmp.Read
    dtaLocation.Recordset.Update

    smEmp.Close
    Set smEmp = Nothing
    '****

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: How add OLE Pic field to Database VB5?

    Because he probably missed the VB5 and Access part. Probably too old to even bother with. It's about 20 years out of date
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How add OLE Pic field to Database VB5?

    The easy way to add a picture into Access 97 from VB5 is by binding a picture box to the data base via a DAO data control.

    If you already have a field which stores pictures in your database you can use the data form wizard in VB5 to create a form that will allow you to add/change the pictures via a bound picture box.
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Jan 2012
    Posts
    35

    Re: How add OLE Pic field to Database VB5?

    Thanks for the response.

    The problem is: I don't know how to insert a field into my database that can hold an OLE object. No such type shows in Visdata's dropdown "Type" box.

    I was wondering if I am going to have to get a copy of Access 2010, create a new database that "can hold an OLE object" and use that in my VB5 program when I call Crystal Reports and insert the Picture from the Access 2010 DB into my Crystal Report form? I'm assuming that Access 2010 allows me to create a field that will hold OLE objects?

    Or can I do it somehow with the Access 3 or 7?

    Thanks for your help!

  8. #8
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How add OLE Pic field to Database VB5?

    I've only did it with Access 97, 2000 and XP and of course SQL Server and MySQL.

    I doubt that VisData supports this as it is really just a sample program that comes with VB5.

    You really should be using something newer than VB5 most people stopped using that years ago.
    Always use [code][/code] tags when posting code.

  9. #9
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: How add OLE Pic field to Database VB5?

    Access 3 ??? That has to be very very old. I am using a 9 year old version and it is version 10 ! i.e. Access 2002 from Office XP

    At any rate there is an option for OLE object as a field type.

    I am sure you could write code to create the field of this type from VB you would just have to do some searching to find the proper script.
    Always use [code][/code] tags when posting code.

  10. #10
    Join Date
    Jan 2012
    Posts
    35

    Re: How add OLE Pic field to Database VB5?

    I got a copy of Access 97, created a new database with an object field, updated the new database with the picture and read it into my Crystal Report just fine. Problem solved.

    Thanks to all of you for the help!!!!

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured