Add Comand

mtagliaferri

Registered User.
Local time
Today, 06:17
Joined
Jul 16, 2006
Messages
550
I have a code that uploads a photo to be displayed on a form and all works well to a certain degree, by clicking on the "Add" on click event once the correct file is selected it returns to the form but the photo has not been updated unless I click on any other fields in the form which then the photo is updated, what should I had to the following code to refresh the form so that the photo is updated once is selected.

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 Photo\Jpg"
        If fDialog.Show = True Then
        strPath = Trim(fDialog.SelectedItems(1))
        DoCmd.RunSQL "update tblCrewMember set Picture = '" & strPath & "' where IDCrewMember = " & CInt(Me.IDCrewMember.Value)
        Else
        End If
    End With
errHandler:
    If (Err.Number = USER_CANC) Then
        Resume Next
    Else
        Exit Sub
    End If
End Sub

Thanks
 
If the "Add" button is in the same form in which you want to show the picture, then try:
Code:
Me.Requery
 
in addition, when you requery you are left on the first record in the recordset, to go back to where you are in the recordset"

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
 
Thanks for your help!
I also have a "Delete" Cmd Button, which I want to delete the pic where there is one; what code is more appropriate to clear the path?
 
just put null value to the field:

Dim lngID As Long
lngID = CLng((Me.IDCrewMember.Value)

DoCmd.RunSQL "update tblCrewMember set Picture = Null where IDCrewMember = " & lngID
Me.Requery
Me.RecordSet.FindFirst "[IDCrewMember] = " & lngID
 

Users who are viewing this thread

Back
Top Bottom