Kamis, 27 Maret 2014

Re: [MS_AccessPros] Work with images with Access using a SQL Server backend.

 

How can I make the adjustment to the code to make sure I get the full path? Path right now would be C:\Work\Unit\Images\Unit 3\Exterior.jpg.

This will change when I move it into production. The path would then be \\CRHANAS\Unit-Info\Unit\EB001

Although EB0001 will change given what ever unit they are looking at. We have a folder per unit.

This is the code for the Add button:

Private Sub cmdAdd_Click()
 ' User asked to add a new photo
Dim strPath As String

    ' If you want to use the Office FileDialog object,
    ' comment out the following code and remove the
    ' comments from the block below
' ***** Begin ComDlg code
    ' Establish a new ComDlg object
    With New ComDlg
        ' Don't allow multiple files
        .AllowMultiSelect = False
        ' Set the title of the dialog
        .DialogTitle = "Locate unit picture File"
        ' Set the default directory
        .Directory = CurrentProject.Path & "\Pictures\"
        ' .. and file extension
        .Extension = "bmp"
        ' .. but show all graphics files just in case
        .Filter = "Image Files (.bmp, .jpg, .gif, .pdf)|*.bmp;*.jpg;*.gif;*.pdf"
        ' Tell the common dialog that the file and path must exist
        .ExistFlags = FileMustExist + PathMustExist
        If .ShowOpen Then
            strPath = .FileName
        Else
            Exit Sub
        End If
    End With
' ***** End ComDlg code
   


        ' Set an error trap
        On Error Resume Next
        ' Set the image
        Me.imgUnit.Picture = strPath
        ' Make sure that "took" OK
        If Err = 0 Then
            ' Got a good file selection ...
            ' See if the photo is in a subpath of this project
            If Left(strPath, Len(CurrentProject.Path)) = CurrentProject.Path Then
                ' Strip it off and store a relative path
                strPath = Mid(strPath, Len(CurrentProject.Path) + 2)
            End If
            ' Set the path in the record
            Me.txtPhoto = strPath
            ' Hide the message
            Me.lblMsg.Visible = False
            ' and reveal the new photo
            Me.imgUnit.Visible = True
        Else
            ' OOOps.
            ' Clear photo
            Me.txtPhoto = Null
            ' Hide the frame
            Me.imgUnit.Visible = False
            ' Clear the image
            Me.imgUnit.Picture = ""
            ' Set the message
            Me.lblMsg.Caption = "Failed to load the picture you selected.  Click Add to try again."
            ' Make it visible
            Me.lblMsg.Visible = True
        End If
    ' Put focus in a safe place
    Me.txtNoteDate.SetFocus


End Sub


This is straight out of the LoadPictureSample.

__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (18)
.

__,_._,___

Tidak ada komentar:

Posting Komentar