Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Picture Field??

Status
Not open for further replies.

allyeric

Programmer
Mar 14, 2000
104
CA
I am trying to create a field in Access 2000 that will hold pictures.  I made the field an OLE object, but not quite sure how that works.  When I added the picture, it creates a package ??  How can I now access that picture using a query in a VB6 program?
 
You need Doogies Magic Picture thingy<br>Step right this way.<br>----------------------<br>I leave the images on the hard drive, Server drive preferrably<br>Then I use this code to load it in an Image on a form<br>This does 2 things allows you to view different formats i.e. .gif or .jpg <br>And keeps your database small because your are not adding images which wil bloat it in a hurry.<br><br>1. So create a form whose record source is connected to your table<br>2. Add an Image to the form<br>3. Properties of Imageas follows<br> Picture (none)<br> Picture Type linked<br>4. Put this code in the On_Current event of the form<br><br>Private Sub Form_Current()<br>&nbsp;&nbsp;&nbsp;&nbsp;If Me![ID] &lt;&gt; 0 Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Me!Image14.Picture = &quot;p:\ViewPhotos\Photos\&quot; & Me![ID] & &quot;.jpg&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Label20.Caption = &quot;File: &quot; & &quot; p:\ViewPhotos\Photos\&quot; & Me![ID] & &quot;.jpg&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>End Sub<br><br>Also I used a unique ID for the Pictures name so when I click the naviagation buttons it would get the unique ID from the database and then load that picture.<br>I also added a label so you know which image it was trying to load (for troubleshooting)<br><br>
 
so in your database field, it is a text field?&nbsp;&nbsp;And the only information you have in there is a picture name?&nbsp;&nbsp;And, when I created an image on the form, I didn't find a picture type in the properties (sorry, pretty new to this)
 
in the Table there is no picture field<br>Just a unique ID field<br>In may case it was &quot;ID&quot; referrdto in the code as Me![ID]<br><br>Then on your form add an &quot;Image&quot;<br><br>So the Image is blank until you open the form.<br>Then the On_current event loads a picture into it when you move back and forth in the records using the navigation buttons.<br><br>
 
I am using the ADO to connect, and my code is a little bit different than yours.&nbsp;&nbsp;I will copy it here, but I have a compile error, as marked in the code for you.&nbsp;&nbsp;I hope you can help me through the fog here.&nbsp;&nbsp;The line in bold is the error line, and the error is with the ampersand as shown in red.&nbsp;&nbsp;The error states Compile Error:&nbsp;&nbsp;Type Mismatch&nbsp;&nbsp;my PictureID field in my table is a text field.<br><br><br>Private Sub Form_Load()<br><br>Dim con As ADODB.Connection<br>Dim rs As ADODB.Recordset<br>Dim strSQL As String<br>Dim lQuestionNumber As Long<br>Dim sQuestion(24), sAnswers(24) As String<br>Dim sPictureID(24) As String<br>Dim intNumber As Integer<br><br>intNumber = 0<br><br>For lQuestionNumber = 1 To 6<br><br>&nbsp;&nbsp;&nbsp;&nbsp;strSQL = &quot;SELECT * FROM Exam_SRHEX44 where Question_No =&quot; & lQuestionNumber<br>&nbsp;&nbsp;&nbsp;&nbsp;Set con = New ADODB.Connection<br>&nbsp;&nbsp;&nbsp;&nbsp;con.Open &quot;DSN=Training;UID=;PWD=;&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;Set rs = con.Execute(strSQL)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;While Not rs.EOF<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sAnswers(lQuestionNumber - 1) = rs(&quot;Answer_Text&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sQuestion(lQuestionNumber - 1) = rs(&quot;Question_Text&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sPictureID(lQuestionNumber - 1) = rs(&quot;PictureID&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rs.MoveNext<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Wend<br>Next<br><br>Pass = frmPassword.txtPassword.Text<br>For C = 1 To Len(Pass)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;R = R + Asc(Mid$(Pass, C))<br>Next<br><br><br>lblQuestion.Caption = sQuestion(intNumber)<br><b>imgExamPic.Picture = &quot;C:\exam pics\&quot; & sPictureID(intNumber)<font color=red> & </font>&quot;.jpg&quot;</b><br>Text1.Text = &quot;File:&nbsp;&nbsp;&quot; & &quot;C:\exam pics\&quot; & sPictureID(intNumber) & &quot;.jpg&quot;<br>chkOptionA.Caption = sAnswers(intNumber)<br><br>End Sub<br><br><br>
 
What is &quot;sPictureID(intNumber)&quot;?<br>Is that that a field on your form<br>then you need &quot;me!&quot; in fron of it<br>If its a field in the ADODB recordset then you need &quot;rs&quot; in front of it.<br>Whatever you put in there has to print out to a valid String name using Debug.print<br>while the code is paused for your error<br>Press ctrl-G to bring up the debug window then type <br>?sPictureID(intNumber) and hit the Enter key it should print out a valid name (whatever the image name your want to load)<br>To test the theory of the Ampersand being the problem or not. Hard code a valid .JPG image name in there temporarily.<br>like:<br>&quot;C:\exam pics\XYZ.jpg&quot;<br>and see if you still get the same error.<br><br>
 
sPictureID(intNumber) is an array into which I put all the data from the picture ID field from the database&nbsp;&nbsp;- which are the picture names.&nbsp;&nbsp;<br><br>Ok, I got it now, we both had it a little off, correct code is:<br><br><br>imgExamPic.Picture = LoadPicture(&quot;C:\exam pics\&quot; & sPictureID(intNumber) & &quot;.jpg&quot;)<br><br><br>thanks for your help!<br><br>
 
Not sure why you are putting the picture field into an array<br>you could think of a table as an array.<br>Then get your answer using a SQL statement.<br>
 
I am putting it into an array because I will be randomizing the pictures before putting it on the form.&nbsp;&nbsp;This is for an exam, and they don't want the questions coming up in the same order every time its run.
 
Hello:
How do I layer pictures in MS Access 2002? What I mean is, I have an embedded .jpg and I want everything else to be in front of it. Watermark or text box transparency doesn't work. The picture (.jpg) still covers the text boxes in my report. I want to be able to select 'send to back' or 'send to front' like in other MS programs but those menus don't seem to appear in Access. I've reset all user commands and still don't see it.
Ideas?
-Jason
 
Hello Jason,
Highlight the control you want to bring in front of the picture, then cut it (Ctrl+X) and right away paste it (Ctrl+V) and place it in the same place it was in, you will find that it will be placed on top of the picture ...
It will keep the same name, values and properties. I hope this will work fine for you ....
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top