Image change whenever it is a new record

luzz

Registered User.
Local time
Today, 00:39
Joined
Aug 23, 2017
Messages
346
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.
 
in the form ONCURRENT event, load the next image.
so when you change record, you get the new img.
 
Or if your image control is called Image1
Code:
Me.Image1.Requery
 
Or if your image control is called Image1
Code:
Me.Image1.Requery

Is this correct? Because it is not working.

Private Sub Form_Current()
Me.Image88.Requery
End Sub

I have remove the control source for the image control.
 
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:

attachment.php


Adapt as appropriate for your own db
 

Attachments

  • Capture.PNG
    Capture.PNG
    5.7 KB · Views: 318
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:

attachment.php


Adapt as appropriate for your own db

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.

i am using single form. I will key in the image path in the garment sketch
 

Attachments

  • form.png
    form.png
    12.9 KB · Views: 108
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

My code:
Private Sub Form_Current()
Me.image88.Picture = Me.txtGarmentSketch
End Sub

The code does not work tho as in the picture does not appear on the form. Or can i use button to browse the image i want to insert in the form?
 
The image field should include the full path+filename+ext of the file not just the filename.
 
sorry, i mean, don't save it like:

Image.bmp
Sketch.png


you must include the complete path:

D:\Folder\Pics\Image.bmp
D:\Folder\Pics\Sketch.png


i hope i explained myself.
 
sorry, i mean, don't save it like:

Image.bmp
Sketch.png


you must include the complete path:

D:\Folder\Pics\Image.bmp
D:\Folder\Pics\Sketch.png


i hope i explained myself.

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

I am able to browse and select the image, but the selected image does not appear on my form
 
Di you have image control on the form
 
Di you have image control on the form

Yes i do have. In order to have a image source have to choose the last icon on the design tab right?
 

Attachments

  • design.jpg
    design.jpg
    93.2 KB · Views: 107

Users who are viewing this thread

Back
Top Bottom