Auto upload picture (1 Viewer)

mtagliaferri

Registered User.
Local time
Today, 17:58
Joined
Jul 16, 2006
Messages
519
I currently have a form for all staff which has a an option to add a photo with the following:

Code:
Private Sub CmdAddPhoto_Click()

On Error GoTo errHandler
 
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
 
    With fDialog
       
        fDialog.AllowMultiSelect = False
        fDialog.Title = "Select photo"
        fDialog.Filters.Clear
        fDialog.Filters.Add "JPEG Pictures", "*.jpg"
        fDialog.Filters.Add "BMP Pictures", "*.bmp"
        fDialog.Filters.Add "PNG Pictures", "*.png"
        fDialog.Filters.Add "All files", "*.*"
        fDialog.ButtonName = "Select"
        fDialog.InitialView = msoFileDialogViewLargeIcons
        fDialog.InitialFileName = CurrentProject.Path & "\Documentation\Crew ID Photos\Jpg"
        If fDialog.Show = True Then
        strPath = Trim(fDialog.SelectedItems(1))
        Dim lngID As Long
        lngID = CLng(Me.IDCrewMember.Value)
DoCmd.RunSQL "update tblCrewMember set Picture = '" & strPath & "' where IDCrewMember = " & lngID
Me.Requery
Me.Recordset.FindFirst "[IDCrewMember] = " & lngID

        Else
        End If
    End With
errHandler:
    If (Err.Number = USER_CANC) Then
        Resume Next
    Else
        Exit Sub
    End If
End Sub

It works perfectly but the users have provided feedback that we don't currently have a photo off all staff and is rather time consuming to check if there is a photo available in the folder.

all the photos are named in the folder as "FirstName Surname StaffNumber"

Is there a way when the form is loaded up to automatically display the picture if available in the folder or leave it blank by looking at FirstName&Surname&StaffNumber?

Hope this makes sense....:eek:
 

RuralGuy

AWF VIP
Local time
Today, 10:58
Joined
Jul 2, 2005
Messages
13,826
Almost certainly but first we will need some additional information. Is there a control on the form to display a picture? If so, what kind of control is it? Do you currently display a picture on the form? Where and how do you get that picture?
 

Orthodox Dave

Home Developer
Local time
Today, 17:58
Joined
Apr 13, 2017
Messages
218
In tblCrewMember, you have the field "Picture", right? And it looks like that only contains the hyperlink to the file on your network - it doesn't contain the picture itself?

Assuming (which we should never do) that if there is a filepath, there must be a picture, then all you need to do is run a query of tblCrewMember where Picture = "".

Or am I missing something?
 

mtagliaferri

Registered User.
Local time
Today, 17:58
Joined
Jul 16, 2006
Messages
519
Yes there is a control on the form called Picture which shows the picture (properties in the attached photo)
This field is in the table too.
 

Attachments

  • Pic 1.PNG
    Pic 1.PNG
    25.1 KB · Views: 108
  • Pic 2.PNG
    Pic 2.PNG
    3.7 KB · Views: 94

isladogs

MVP / VIP
Local time
Today, 17:58
Joined
Jan 14, 2017
Messages
18,242
The attached database may be useful to you.
Its used to display thumbnail images for selected images in a folder

I uploaded it some time ago for another thread but can't remember where ...

You may be able to adapt the code for your purposes

Also for a situation similar to yours, I have a default image 'NoPhoto.bmp' which is displayed where no photo exists for a particular person

Also attached in case its any use to you...

HTH
 

Attachments

  • FolderImages EMPTY.accdb
    700 KB · Views: 41
  • NoPhoto.bmp
    71.5 KB · Views: 54

RuralGuy

AWF VIP
Local time
Today, 10:58
Joined
Jul 2, 2005
Messages
13,826
Let us know if you still need assistance. This is a solvable issue, probably with code.
 

mtagliaferri

Registered User.
Local time
Today, 17:58
Joined
Jul 16, 2006
Messages
519
I am an amateur :D
Everything I have accomplished is with the help of you buys!!

Yes I would more likely need more help!
The attached database may be useful to you.
Its used to display thumbnail images for selected images in a folder

I uploaded it some time ago for another thread but can't remember where ...

You may be able to adapt the code for your purposes

Also for a situation similar to yours, I have a default image 'NoPhoto.bmp' which is displayed where no photo exists for a particular person

Also attached in case its any use to you...

HTH
Is very interesting and somewhat helpful, but I would not know how to put in practice :confused:
 

isladogs

MVP / VIP
Local time
Today, 17:58
Joined
Jan 14, 2017
Messages
18,242
As the quote is from my post, here is some more info about the Image Display database:

Click the Populate Image List button then select a folder containing images.
This will add all the images to the listbox.
Select any image from the list to view a thumbnail :



For info, GIF, PNG & BMP images display better in Access than the 'lossy' JPG image format

The 4 lines of code used below are the part that may be useful to you:

Code:
Private Sub lstImages_Click()

On Error GoTo Err_Handler

  Me.ImageFrame.Visible = True
  Me.ImageFrame.Picture = Me.lstImages
  Me.txtImageName = Me.lstImages.Column(1)
  Me.txtImageName.Visible = True

Exit_Handler:
    Exit Sub

Err_Handler:
    strProc = Application.VBE.ActiveCodePane.CodeModule.ProcOfLine(Application.VBE.ActiveCodePane.TopLine, 0)
    MsgBox "Error " & err.Number & " in " & strProc & " procedure : " & vbNewLine & _
        err.Description, vbExclamation, "Error"
    Resume Exit_Handler

End Sub

For your purposes, any staff without a photo could be assigned a default image in the image file path.

You can also click the View All Images button to open a report showing thumbnails of all images in a folder (though that's not relevant to your current needs)



If you have any questions, get back to me
 

Attachments

  • ImageDisplayForm.jpg
    ImageDisplayForm.jpg
    89.9 KB · Views: 201
  • ImageDisplayReport.jpg
    ImageDisplayReport.jpg
    102.5 KB · Views: 237
Last edited:

mtagliaferri

Registered User.
Local time
Today, 17:58
Joined
Jul 16, 2006
Messages
519
Thanks Ridders, I have learned a lot and played around the DB sample, still well complicated for me to understand all.
I have found a way round in a certain way.... I have used and AfterUpdate to write a value in a txtbox called photo, I have created a picture field in the form where the source is 'photo'
How to I get the afterupdate to write the entire path + the 'StaffNumber' + jpg (I will convert all photos to PNG as you have suggested).
the cuurent path is:
Code:
C:\Users\User\Desktop\Documentation\Staff Photos\123456.jpg
but I have to keep in mind that all the photo are stored in a sharepoint folder.
I also seems that this way if the file does not exhist it simply does not display anything and no errors flag up!
 

Attachments

  • DB Photo Staff.accdb
    412 KB · Views: 42

isladogs

MVP / VIP
Local time
Today, 17:58
Joined
Jan 14, 2017
Messages
18,242
Here you go...

I've done the following to allow you to populate the Photo field.
It uses the photo path where it exists or replaces with a default 'no photo' image where the staff photo isn't available

Changes made:
1. Added 2 fields to tblStaff: PhotoPath(text); PhotoExists (Yes/No)
2. Added a module modUpdateStaffPhotos with 3 functions:
- UpdateStaffPhotos / ClearStaffPhotos / FileOrDirExists

NOTE:
a) FileOrDirExists is used to check if there is a specified file in the specified location
b) Modify the 3 string values in UpdateStaffPhoto function as necessary
c) Run UpdateStaffPhotos procedure to populate the 2 new fields and then modify the Photo path depending on whether the photo actually exists
d) ClearStaffPhotos is only there if you want to clear the data and start again
 

Attachments

  • DB Photo Staff - updated CR.accdb
    632 KB · Views: 43

mtagliaferri

Registered User.
Local time
Today, 17:58
Joined
Jul 16, 2006
Messages
519
Thanks for your help,
I have updated the path, and leaving the jpg currently till I change the format, but one silly question...how do I run the update photo function, is that suppose to rune every time the form is opened?
 

isladogs

MVP / VIP
Local time
Today, 17:58
Joined
Jan 14, 2017
Messages
18,242
You could do that by adding it to Form_Load event

Alternatively as part of an Autoexec macro etc. Up to you
 

mtagliaferri

Registered User.
Local time
Today, 17:58
Joined
Jul 16, 2006
Messages
519
Lost again...
I created the macro, but not running the function
 

Attachments

  • 1.PNG
    1.PNG
    6.2 KB · Views: 62

isladogs

MVP / VIP
Local time
Today, 17:58
Joined
Jan 14, 2017
Messages
18,242
You need to use brackets after the function name: UpdateStaffPhotos()
Save the macro as autoexec

It will then run when the db is opened.
However if any photos are added after the db is opened these won't be updated unless the function is run manually

If you instead use the Form_Load event, it will update each time the form is used.
It should only take a fraction of a second even if you have lots of records
 

Users who are viewing this thread

Top Bottom