Hi guys, am facing a issue whereby my image is the same on my form even if i have change to another data with a different image.
How can i solve this? I use control source to tied the image control on the form.
I am thinking maybe VBA code would be able to help me solve this issue, however i do not have any idea how to code that. I am assuming the code should be written on the form.
It will work providing you've set code to update it to the correct record.
It may be that the code should be in another form event?
For example I have a form used to select students from a listbox lstPupilID,
When a selection is made, this code runs & the PupilPhoto image control is both made visible & updated:
Code:
Private Sub LstPupilID_Click()
On Error GoTo Err_Handler
Me.PupilID = Me.LstPupilID
PupilPhoto.Requery
PupilPhoto.visible = True
etc
End Sub
For this to work, the record source for the photo is as follows:
It will work providing you've set code to update it to the correct record.
It may be that the code should be in another form event?
For example I have a form used to select students from a listbox lstPupilID,
When a selection is made, this code runs & the PupilPhoto image control is both made visible & updated:
Code:
Private Sub LstPupilID_Click()
On Error GoTo Err_Handler
Me.PupilID = Me.LstPupilID
PupilPhoto.Requery
PupilPhoto.visible = True
etc
End Sub
For this to work, the record source for the photo is as follows:
I have a code whereby i will click on edit so that the data from subform appear on my form. When the data is on my form i will key in the image path before i save it. Is that consider as update?
Not quite sure I understand what you're saying but I don't think so.
I always have the image path saved in a table for all situations like this.
The code then finds the path & updates the image using the requery code.
Hope that makes sense.
Not quite sure I understand what you're saying but I don't think so.
I always have the image path saved in a table for all situations like this.
The code then finds the path & updates the image using the requery code.
Hope that makes sense.
oh yeah! That's what i am doing now is to store the image path for each of my PO. I do not have a button to click like yours. So i will have to have my code in the form current right?
Sorry luzz, if your form is continuous form, there is no fux for this. The only eay you can change the pics in this kind of form is to have one image control on the form header or footer. Or use single form.
Sorry luzz, if your form is continuous form, there is no fux for this. The only eay you can change the pics in this kind of form is to have one image control on the form header or footer. Or use single form.
if you already have the path on the field on your
table, add that field in your form.
you can make it's Visible Property to No, in
case you don't want to show it.
then on the Current Event of the Form change the Picture
property of the Image Control to the path of the picture:
Private Sub Form_Current()
Me.yourImageControlName.Picture = Me.yourPicturePathField
End Sub
if you already have the path on the field on your
table, add that field in your form.
you can make it's Visible Property to No, in
case you don't want to show it.
then on the Current Event of the Form change the Picture
property of the Image Control to the path of the picture:
Private Sub Form_Current()
Me.yourImageControlName.Picture = Me.yourPicturePathField
End Sub
Hmm, if i set the path like this, means that my image will only that path then if i wan to have a new image for the next data i will have to set the path again?
to save you from trouble of putting the path.
add a CommandButton on your form.
put a descriptive Caption to the button, eg: "Add/Update Image"
On the Click Event of this button, call the FileDialog.
then update the textbox on your form that saves the path
( make sure to add the imagepath field in your form):
Code:
Private Sub button_Click()
Dim strPicturePath As String
strPicturePath = PicturePicker()
If strPicturePath <> "" Then
Me.yourImagePathTextbox=strPicturePath
me. Image. Requery
Me.Dirty = False
End If
End Sub
...
on VBE, add reference to Microsoft Office XX.X Object Library.
XX.X is ther version of Office installed on your system.
now save this to a Standard Module:
Code:
Public Function PicturePicker( _
Optional ByVal strWindowTitle As String = "Select a Picture file") As String
Dim fd As Office.FileDialog
'Set fd = Application.FileDialog(msoFileDialogFolderPicker)
Set fd = Application.FileDialog(msoFileDialogFilePicker)
If strDirectory = "" Then strDirectory = "c:\Documents"
With fd
.Title = strWindowTitle
.Filters.Add "Pictures", "*.bmp;*.png;*.jpg;*.jpeg;*.gif", 1
.AllowMultiSelect = False
If .Show = -1 Then
FilePicker = (.SelectedItems(1))
Else
FilePicker = vbNullString
End If
End With
Set fd = Nothing
End Function
leave the Current Event of the Form as is:
Private Sub Form_Current()
If Not Me.NewRecord Then _
Me.Image.Picture = Me.yourImagePathTextbox
End If
End Sub
to save you from trouble of putting the path.
add a CommandButton on your form.
put a descriptive Caption to the button, eg: "Add/Update Image"
On the Click Event of this button, call the FileDialog.
then update the textbox on your form that saves the path
( make sure to add the imagepath field in your form):
Code:
Private Sub button_Click()
Dim strPicturePath As String
strPicturePath = PicturePicker()
If strPicturePath <> "" Then
Me.yourImagePathTextbox=strPicturePath
me. Image. Requery
Me.Dirty = False
End If
End Sub
...
on VBE, add reference to Microsoft Office XX.X Object Library.
XX.X is ther version of Office installed on your system.
now save this to a Standard Module:
Code:
Public Function PicturePicker( _
Optional ByVal strWindowTitle As String = "Select a Picture file") As String
Dim fd As Office.FileDialog
'Set fd = Application.FileDialog(msoFileDialogFolderPicker)
Set fd = Application.FileDialog(msoFileDialogFilePicker)
If strDirectory = "" Then strDirectory = "c:\Documents"
With fd
.Title = strWindowTitle
.Filters.Add "Pictures", "*.bmp;*.png;*.jpg;*.jpeg;*.gif", 1
.AllowMultiSelect = False
If .Show = -1 Then
FilePicker = (.SelectedItems(1))
Else
FilePicker = vbNullString
End If
End With
Set fd = Nothing
End Function
leave the Current Event of the Form as is:
Private Sub Form_Current()
If Not Me.NewRecord Then _
Me.Image.Picture = Me.yourImagePathTextbox
End If
End Sub