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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Images To Forms 4

Status
Not open for further replies.

randy21m

Technical User
May 13, 2004
8
US
I have been working on a db now for about 2 weeks and have everything flowing smoothly....until I came to adding .jpg or .bmp into the form. I'm not an access expert and I'm only going off of everything I've been reading in forums so if anyone could please help with some instructions it would be greatly appreciated. The way I have things set up are as follows:
1st Combo box shows "set":
Click on a certain "set" to reveal "name" in the next combo box:
Now what I want to happen when you click on the name is for the picture to come up when you click on a specific name.
If anyone could help you would save me from throwing my computer out the window for it feels like I have tried everything!
 
It sounds like you are trying to do something similiar to what I have done just recently.
1st) Do you have a way of specifying the image. IE C:\path\image.jpg ?

2nd) do you know how to edit a form and put any old image on it?

3rd) goto properties of the image you put on in step 2 and change it to the valu in step 1 IE me.text11

If you can't get it from that look for old posts I started and read them. Someone told me how to do it within the past month or so. (I was trying to do Autocad thumbnails)


 
try threads 702-289543 and thread 702-831482. Wish I knew how to point to them.

javascript:gothread(702.831482)
 
to point to a thread remove the space between thread and the number ie thread702-289543 and thread702-831482

Hope this helps
Hymn
 
Thankyou, Things can be so easy to learn and so hard if you never try. I found out about underline and bold while looking for this info just now.

 
How are ya randy21m . . . . .

[blue]The main trick here is to be able to [purple]reference the 'Graphic' Path & File Name[/purple] for each name in the combobox[/blue]
. You can add a field to the same table that holds the Name or you could make a seperate table.

Next, get all your graphic (or copies thereof) into a common folder.

Next you add the new field to the [blue]RecordSource[/blue] of the combobox. The new field doesn't have to show.

Now add an Image Control (it must be an Image Control, not the others) to the form.

Then in the AfterUpdate event of the combo add the following line:

Me![purple]ImageControlName[/purple].Picture = Me![purple]ComboboxName[/purple].Column(?)

Where "?" is the column number -1.

cal.gif
See Ya! . . . . . .
 
Hey TheAceman1, thanks for your help as well as FacilitiesCAD, I still have a couple questions however. Now Aceman1, I already have the "Name" field created that links to the "set" combo box. So I put the code in the "after update of the "name" combo? The you say "the new field doesn't have to show"?? What exactly does that mean? I'm not around my db until tomorrow so I'm not getting to try all this right now. But thank you all very much for all your help and I'll be trying all day tomorrow to make things work. Thanks again....
 
OK randy21m . . . . .
randy21m said:
[blue]I already have the "Name" field created that links to the "set" combo box.[/blue]
By this you should mean you have the field containing the [blue]Path & FileName[/blue] to each graphic in the combobox as well. Is this so?

To find the name of a control, open properties for the control and click the [blue]Other Tab[/blue]. At the top is the [purple]Name Property[/purple] of the control. This is what you replace the [purple]purple[/purple] text with in the code.
randy21m said:
[blue]The you say "the new field doesn't have to show"?? What exactly does that mean?.[/blue]
When you drop the Set Combobox, you really only wanna see the name. Not the Path & Filename too. This will be hidden. You do this by setting the [blue]Column Count[/blue] property to the number of fields ya wann show. Then setting the widths of the columns with the [blue]Column Widths[/blue] property. Any width you set to zero, the field is there, just hidden, and available to the code.

If ya have any problems let us know . . . . . .


cal.gif
See Ya! . . . . . .
 
Hey Aceman,
No, I don't have any links to any graphics at this point. The only thing I have is the "set" combo box that shows all the sets, then I have the "name" combo box that shows all the "names" in each "set". Now I want to link the .jpg with each individual name in each set. I found some good threads on here that I'm gonna try out today. But any other advice you can give is always welcome. Thanx so much for you all your help.
 
Ok, I have toyed with this and can't seem to get it working.
1st- I created the correct path name to my image and put it on my table. I put it in my column specifically named "pic" next to the corresponding "name".
2nd- I created a txtbox with the name "ImagePath". I set the visible field to "no" and did nothing else.
3rd- I created an image box with the name "PictureImage". I deleted the selected image from the appropiate field.
4th- I selected the forms properties and on the "on current" field I typed "Me![PictureImage].Picture = Me![ImagePath].
5th- I keep getting an error= Run time error 2220, Microsoft can't open the file (where I stored the file)???

I'm stuck at this point. I didnt add in anything except that! Yet I get this error and it won't show me the image? Please help. I have tried a couple different things but nothings working.
 
randy21m . . . . Wow! . . . .

It looks like I'm gonna have to step you thru this. So remove the pic field you added to the table, delete the textbox you made, and delete the code you put in the On Current event. I'm gonna need the following info befor I can continue:

The Table Name?
The Table PrimaryKey Name? (I assume data type is numeric).
The Name Field Name? (unless it is "Name")
Set Combobox Name?
Name Combobox Name?

I await! . . . . .



cal.gif
See Ya! . . . . . .
 
Follow aceman1 advice. I am a novice. BUT from your description I think I understand what went wrong.

1) In the textbox "ImagePath" set it back to visible = yes, you are doing this just so you can see it while we debug it.

2) in the textbox "ImagePath" type "= pic & name" without quotes. Now when your on an entry "ImagePath" should say "c:\dir1\dir2\image.jpg" If it doesn't say something exactly like this you need to modify youre text box so it does ie "ImagePath" = "c:\" & pic & "\" & name & ".jpg"

3) onec you have the text box "ImagePath" just how you want it. Set "PictureImage" picture property to "=ImagePath"

4) if you get all this to work, you can set "ImagePath" visible to no so it doesn't display on the screen.

If this doesn't help you remember TheAceMan1 is ready to help you and there is a reason he is listed as a programmer and I'm just a technical user.

Tim
 
Hey Aceman1,

Sorry, I was gone all weekend and didn't get to read this until just now.
1. Table Name = "YuGiOh"
2. I didn't set a primary key on the table.
3. Name field on the table = "name"
On the form combo box = "cboNameField"
4. Set field on the table = "Set"
On the form combo box = "cboSetField"

I hope this helps? FacilitesCAD, I didn't get a chance to try what you posted, but while I await Acemans reply, I will give it a shot. Aceman1, Thanks for all your help and your patience. I really thought I had this nailed from your previous advice, but I am a beginner in access and feel pretty good that I got this far without having to have help from anyone, so anyway, thanks again.
 
Ok, FacilitesCAD or Aceman1,
I have the textbox set up correctly atleast I think I do. Without the image being set, when I click on a certain "name", it shows the path to the picture in the text box. However, when I tried to enter "=ImagePath" in the picture setting of the "PictureImage", it will not let me do this. It tells me that Microsoft cannot find that setting?? Then I tried to put that code in the After Update field of the ImagePath combo box, and nothing. Then I tried to put it on the On Current of the form, and runtime error again. It tell me that Microsoft cannot open...."that directory"?? But I do have the text box set up correctly. Any other help on this?
 
randy21m . . . .

Havn't forgot ya . . . Can't post till later this afrernoon, but I will step you thru it!

Hang in there! . .

cal.gif
See Ya! . . . . . .
 
Sorry Randy,
I can't help you right now. I have a slightly bigger problem right now. My wife has walked out on me. I probable won't be on this board for a while. Aceman should get you through this. Once I pick up the peices of my life I'll be back on and maybe I can help you with a new problem. One thing I've found with Access is that once I figure out one problem with it I can easily find a tougher one.

Tim
 
FacilitesCAD, wow, sorry man. Hang in there and good luck to you. Hope to hear from you in the future.
Aceman1, no problem. I will continue to search around and play with this until I hear from you. Thanks again for both of your help.
 
OK randy21m . . . . . . Sorry to get back so late!

I built this up over time and its a little extensive. If anywhere in the sequence of instructions you have a problem, stop there and let me know.

[highlight][green]Step 1[/green][/highlight]
Never make a table without a [blue]Primary Key[/blue] (PK). So in your [blue]YuGiOh[/blue] table, insert a line at the top with the following:
[blue]Name = YugiOhID
Type = Auto Number[/blue]

Add the following field (this will hold the path * filename to all your graphics)
[blue]Name = picPath
Type = Text
Field Size = 255[/blue]

Save & Close the table.

[highlight][green]Step 2[/green][/highlight]
Make a query that includes the Pk, Name, and picPath fields. Set your sorting on the name field. Name the query [blue]qryPic[/blue]

[highlight][green]Step 3[/green][/highlight]
Make a conitnuous form using [blue]qryPic[/blue] as the [purple]Record Source[/purple] (this is the form you'll use to edit/set the paths to your picture files). Put the Name & picPath controls on the form. Then, set the following on the Forms Format Porperties Tab:
[blue]Default View = Continuous
Scroll Bars = Verticle Only
Auto Resize = Yes
AUto Center = Yes
Border Style = Thin[/blue]

On the Data Properties Tab for the form set the following
[blue]Allow Additions = No[/blue]

On the Other Properties Tab set the following
[blue]Pop Up = Yes[/blue]
Save the form (do not close it. leave it in design view)

[highlight][green]Step 4[/green][/highlight]
I decided to make it easy for you to enter your picture Path & FileNames by incorperating the [purple]Common Dialog Control[/purple] (don't ask . . . just keep going!). Wether or not this can be done depends on your version of Access.

So on the MenuBar click Insert - ActiveX Control... A dialog opens. Scroll down thru the list. Your looking for: [purple]Microsoft Common Dialog Control, version 6[/purple]. If you don't find it, you'll have to enter your Path & FileNames manually ([purple]in this case goto Quote 5[/purple]).

If do have it, select it and click OK. A small square button will appear on the form. Just leave it, its hidden in form view.

In the Other Properties Tab for the new control, set the Name Property at the top:
[blue]Name = axCom[/blue]

Now . . . . in the [blue]DoubleClick Event[/blue] for the [blue]picPath[/blue] control, add the following code:
[blue]Dim axCtl As Object

Set axCtl = Me!axCom

axCtl.DialogTitle = "Insert Picture Path & FileName"
axCtl.InitDir = "D:\Graphics\Misc"
axCtl.Filter = "Bitmaps (*.bmp)|*.bmp|Jpegs (*.jpg)|*.jpg|Gifs (*.gif)|*.gif"
axCtl.ShowOpen
Me!Text3 = axCtl.FileName

Set axCtl = Nothing[/blue]

Compile & Save and close the form

[highlight][green]Step 5[/green][/highlight]
Test the form by entering a few paths (manually, or by double-clicking picPath if you were able to install the Common Control) in the first few records.

I'm gonna stop here and see if you can get this far.

Let me know! . . . . .


cal.gif
See Ya! . . . . . .
 
AceMan,
I hope he can get it because I lost track along the way in your direction. Probable just because I'm not making one at the same time. I'm off to Ireland for a vacation (10 days) but after that I should be back on the forumn. I may spend a little time this morning playing with this project because I don't want to start anything new before leaving on a half day (and keeping busy keeps my mind of my wife)

Talk to you later.

Tim
 
OK Randy,
I just spent a few minutes trying this out.

Code:
Private Sub Form_Current()
Image4.Picture = Me.Text5
End Sub

Private Sub Image4_Click()
Image4.Picture = Me.Text5
End Sub
[/c]

There is two sets of code that both worked for me.  The first one is probable a better choice.
basically my picture is Image4.  I just selected the image choice from my toolbar and put it the size I wanted.  I selected a jpg file for my first image.

I think you got this close when you responded back earlier.  Next in the design view select the entire form.  The spot to do this is in the top left corner.
goto the on current property and select event procedure.
when you go to edit the procedure it should look something like this:

Private Sub Form_Current()

End Sub

just put in the program you want Image#.picture= me.text#

I ran into the same problems you did when I didn't make it an event procedure.  The other thing you must be absolutely sure of is that you have the whole path file name spelled correctly bassed on how the computer thinks it is.  The way I check this is by looking in the picture property box that I first pulled the image in with.

C:\Dir1\IMAGE001.jpg

It is easy to miss a \ or C:\ or .jpg if you don't know you need it.

Good luck.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top