private combo_afterupdate()
select case combo
case "Item 1"
me.image1.picture = "c:\img\image1.png"
case "Item 2"
me.image1.picture = "c:\img\image2.png"
end select
end sub
Thanks a lot everybody
I want to show the image of the item I select from the combobx inside a field called (Pic) in the same subform.
See the attachment (I made it in paint).
Thanks
private combo_afterupdate()
select case combo
case "Item 1"
me.image1.picture = "c:\img\image1.png"
case "Item 2"
me.image1.picture = "c:\img\image2.png"
end select
end sub
Thanks for your reply
This is my code and it is not working for some reason:
Private Sub PR_Items_AfterUpdate(Cancel As Integer)
Select Case PR_Items
Case "Adult Standard Walker"
[Forms]![frmPatient]![PrescribedItems_Subform3].[Form]![Image76].Picture = "C:\Users\hsghazal\Desktop\AdultStandardWalker.jpg"
Case "Standard Cane"
[Forms]![frmPatient]![PrescribedItems_Subform3].[Form]![Image76].Picture = "C:\Users\hsghazal\Desktop\StandardCane.jpg"
Case "Adult Wheeled Walker"
[Forms]![frmPatient]![PrescribedItems_Subform3].[Form]![Image76].Picture = "C:\Users\hsghazal\Desktop\AdultWeeledWalker.jpg"
End Select
End Sub
Where is the picture control? If it is on the same form as the selection, then just use Me.Image76.Picure to set it. If it is on the parent form, then use Me.Parant.Image76Picture.
Hardcoding stuff like this just makes the app inflexible and not expandable. What if you get a fourth product or a tenth? You need a product table with description, price, etc. Add another field to the table to hold the path to the picture. Then you need ONE line of code no matter if you have 3 products or thousands!!!
Me.ProductPic.Picture = Me.PicturePath.
How you get the PicturePath depends on how you are entering products. If you are using a combo, you can add the PicturePath as the third fiekd if tge RiwSource. Then the code would be:
Me.ProductPic.Picture = Me.cboProductID.Column(2)
Note that the RowSource of the combo is a zero based array so the third column is referenced as 2 because the first one is referenced as 0. Make the length of the PicturePath field 0 so it doesn't show when the combo is expanded.
And get in the habit of assigning rational names to controls BEFORE you write code to reference them. Good practices matter.
Northwind Downloads Microsoft provide some very nice downloadable databases which you can use to get an insight into how Microsoft Access functions. In particular, and I believe it was the first, or at least one of the first examples, "The Northwind Database" is a fine example of an invoicing...
Where is the picture control? If it is on the same form as the selection, then just use Me.Image76.Picure to set it. If it is on the parent form, then use Me.Parant.Image76Picture.
Hardcoding stuff like this just makes the app inflexible and not expandable. What if you get a fourth product or a tenth? You need a product table with description, price, etc. Add another field to the table to hold the path to the picture. Then you need ONE line of code no matter if you have 3 products or thousands!!!
Me.ProductPic.Picture = Me.PicturePath.
How you get the PicturePath depends on how you are entering products. If you are using a combo, you can add the PicturePath as the third fiekd if tge RiwSource. Then the code would be:
Me.ProductPic.Picture = Me.cboProductID.Column(2)
Note that the RowSource of the combo is a zero based array so the third column is referenced as 2 because the first one is referenced as 0. Make the length of the PicturePath field 0 so it doesn't show when the combo is expanded.
And get in the habit of assigning rational names to controls BEFORE you write code to reference them. Good practices matter.
I have little experience in Access, so Its sometimes hard form me to figure it out easily.
As in the following attached picture, I need an image to appear in a new field beside the combobox field inside the subform when the user choose a specific selection.
Now the answer to your question "where is the picture control" is: I drag and drop it inside the subform (tblPrescribedItems Subform3) in design view as the below pic:
Now I don't understand this paragraph: "Note that the RowSource of the combo is a zero based array so the third column is referenced as 2 because the first one is referenced as 0. Make the length of the PicturePath field 0 so it doesn't show when the combo is expanded".
And what is the vba line that I should write to refer to the image inside the subform.
When you bring in the data for your combo, you should bring in
PKID
Description
PathToImageFile
as Pat stated, make width of 3rd column 0, same is the ID column.
That means you need to store the path in the table where the combo descriptions are?
I am not sure how to just use the values in the source for Picture, so I would use code like below.
Code:
Private Sub cboFiles_AfterUpdate()
Dim strPath As String
strPath = Me.cboFiles.Column(2) & Me.cboFiles.Column(1)
Debug.Print strPath
Me.imgPic.Picture = strPath
End Sub
The debug.print is to check my value, comment out/remove when working.
My combo is
Code:
SELECT Files.FileID, Files.FName, Files.FPath
FROM Files
ORDER BY Files.[FileID];
When you bring in the data for your combo, you should bring in
PKID
Description
PathToImageFile
as Pat stated, make width of 3rd column 0, same is the ID column.
That means you need to store the path in the table where the combo descriptions are?
I am not sure how to just use the values in the source for Picture, so I would use code like below.
Code:
Private Sub cboFiles_AfterUpdate()
Dim strPath As String
strPath = Me.cboFiles.Column(2) & Me.cboFiles.Column(1)
Debug.Print strPath
Me.imgPic.Picture = strPath
End Sub
The debug.print is to check my value, comment out/remove when working.
My combo is
Code:
SELECT Files.FileID, Files.FName, Files.FPath
FROM Files
ORDER BY Files.[FileID];
Where is the picture control? If it is on the same form as the selection, then just use Me.Image76.Picure to set it. If it is on the parent form, then use Me.Parant.Image76Picture.
Hardcoding stuff like this just makes the app inflexible and not expandable. What if you get a fourth product or a tenth? You need a product table with description, price, etc. Add another field to the table to hold the path to the picture. Then you need ONE line of code no matter if you have 3 products or thousands!!!
Me.ProductPic.Picture = Me.PicturePath.
How you get the PicturePath depends on how you are entering products. If you are using a combo, you can add the PicturePath as the third fiekd if tge RiwSource. Then the code would be:
Me.ProductPic.Picture = Me.cboProductID.Column(2)
Note that the RowSource of the combo is a zero based array so the third column is referenced as 2 because the first one is referenced as 0. Make the length of the PicturePath field 0 so it doesn't show when the combo is expanded.
And get in the habit of assigning rational names to controls BEFORE you write code to reference them. Good practices matter.