Solved

Help in Inserting Picture (jpg,bmp,etc..) in a table ---- OLE OBJECT

Posted on 2004-08-29
15
439 Views
Last Modified: 2008-02-01
I know this ought to be simple and easy.. and I  might need it right away.. who knows what could happen.. :)

I got this database with a table named "users" with ID, NAME, PICTURE as fields
ID and NAME are strings while PICTURE is an OLE Object field...

these are about 100+ records and I got also 100+ jpg pictures in a folder for each user.. How do I put all of those pictures in the OLE Object field (batch) with a VBA procedure/function

and what is the library of ADODB.STREAM.. I cant seem to find it.. (no STREAM option in ADODB)

thanks,
RLBE
0
Comment
Question by:RLBE
  • 9
  • 6
15 Comments
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11926001
Don't store pictures in an OLE field. You'll get an enormous amount of database bloat - you can expect a 30KB JPG to increase your db size by about 1MB.

Instead, just store the filename and path of the JPG file against each record and when you need to display them, set an Image control's Picture property.
0
 

Author Comment

by:RLBE
ID: 11926089
hmmm..

but just in case I need to insert the picture in the Ole object itself with VBA code, how is it done...

or correctly done? Im not considering the bloat factor that much now...

thanks in advance...
0
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 125 total points
ID: 11926130
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:RLBE
ID: 11926251
I cant seem to understand how the [OLE***] works since I cant get the "." values... (in the link given above, ie. ".sourcedoc" ".action", etc...)

sorry.. anyway.. I might not understand since Im focused in a single function anway I'm stuck at this code and got errors on anything else I try..

--------------------------
--------------------------

Function picuser()
On Error GoTo eer
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim path
Set db = CurrentDb
Set rs = db.OpenRecordset("users", dbOpenDynaset)
rs.MoveFirst
While rs.EOF = False

rs.Edit
path = "C:\images\" & rs.Fields("issn") & ".jpg"

rs.Fields("picture") = path                                        'the OLE object // not working this is not right
rs.Update

eer:
rs.MoveNext
Wend

End Function
0
 

Author Comment

by:RLBE
ID: 11926267
sorry.. I forgot.. i renamed ID field to "issn"
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11926291
That simply won't work, I'm afraid. You need to follow the instructions in the article - read it carefully, you need to create a form with an OLE object frame in it, based (in this case) on your customers table. Let me know which parts of the article you're having difficulty with.
0
 

Author Comment

by:RLBE
ID: 11926335
okay.. Im going to work on the sample code from the form right away...
0
 

Author Comment

by:RLBE
ID: 11926420
I followed exactly the instructions on the link...

I also got a bmp file in the folder and jpg's (is paint.picture applicable to jpg too?)

now there is no output.. the MyFile is blank as in "" (in debug) while the path is okay..

and the table still contains nothing.. :)

thanks.. :)

-------------
3 text boxes..
"the path"
*.bmp
Paint.Picture
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11926448
OK, what have you set the SearchExtension to? Can you post the code that you have actually put in your form? With the method in the link, you can only insert one type of extension at a time (i.e. you need to do bmp files first and then jpgs).
0
 

Author Comment

by:RLBE
ID: 11926502
Ah okay.. here's the code

Option Compare Database

Private Sub cmdloadole_Click()
Dim MyFolder As String
       Dim MyExt As String
       Dim MyPath As String
       Dim MyFile As String
       Dim strCriteria As String

       MyFolder = Me!searchfolder
       ' Get the search path.
       MyPath = MyFolder & "\" & "*." & [searchextension]
       ' Get the first file in the path containing the file extension.
       MyFile = Dir(MyPath, vbNormal)
       Do While Len(MyFile) <> 0
          [olepath] = MyFolder & "\" & MyFile
          [olefile].Class = [oleclass]
          [olefile].OLETypeAllowed = acOLEEmbedded
          [olefile].SourceDoc = [olepath]
          [olefile].Action = acOLECreateEmbed
          ' Check for next OLE file in the folder.
          MyFile = Dir
          ' Go to new record on form.
          ' For Access 95 only, use the following Line of code:
          DoCmd.DoMenuItem acFormBar, acEditMenu, 12, 4, acMenuVer70

          ' For Access 97 only, use the following line of code:
          'DoCmd.RunCommand acCmdRecordsGoToNew
       Loop
 End Sub

0
 

Author Comment

by:RLBE
ID: 11926506
I just copied it directly so as not to incurr errors...
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11926524
OK, what did you type into the SearchExtension text box when you ran the code? Try typing in just:
bmp

and see what that does.
0
 

Author Comment

by:RLBE
ID: 11926572

geesh.. I forgot.. sorry, I didnt see that there is already an *.

thank you very much.. I got the code working now.... I'd just tweak it a little to for it to work for the one I'm solving... and automate it..

thanks for the help...

0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 11926579
No problem, don't forget to close and grade this question! :-)
0
 

Author Comment

by:RLBE
ID: 11926583
thanks for the solution.. and the time.. :)

-solution accepted-
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question