Jumat, 30 Mei 2014

Re: [MS_AccessPros] Re: Working with PDFS in Access 2013

 

I am uploading a dumb down version of the database so you can look at in the Needs Assistance folder. Just open it and fire up the ApplicantDetail form and then goto the Note tab.
 

With Warm Regards,
 
Arthur D. Lorenzini
IT System Manager
Cheyenne River Housing Authority
Wk.(605)964-4265  Ext. 130
Fax (605)964-1070
"Only those who will risk going too far can possibly find out how far one can go."






On Friday, May 30, 2014 9:26 AM, "Art Lorenzini dbalorenzini@yahoo.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com> wrote:


 
John,
I do its called txtPhoto. I based this off the sample database found on this site. But for some reason it is not saving the path or pulling in the PDF to the OLE control. This is the code as it sits now.

Private Sub Form_Current()
' Load the current image, if any, when moving to new row
Dim strPath As String
    ' If on new record,
    If Me.NewRecord Then
        ' Then set the message
        Me.lblMsg.Caption = "Click Add to create a photo for this note."
        ' Make it visible
        Me.lblMsg.Visible = True
        ' .. and hide the image frame
        Me.imgPDF.Visible = False
        Exit Sub
    End If
   
    ' Try to load image - set error trap
    On Error Resume Next
    ' If nothing in the photo text,
    If IsNothing(Me.Photo) Then
        ' Then set the message
        Me.lblMsg.Caption = "Click Add to create a photo for this note."
        ' Make it visible
        Me.lblMsg.Visible = True
        ' .. and hide the image frame
        Me.imgPDF.Visible = False
    Else
        strPath = Me.Photo
        ' Check for characters that indicate a full path
        If (InStr(strPath, ":") = 0) And (InStr(strPath, "\\") = 0) Then
            ' Just a file name, so add the current path
            strPath = CurrentProject.Path & "\" & strPath
        End If
        ' Attempt to assign the file name
        'Me.imgPDF.Picture = strPath
        Me.imgPDF.SourceDoc = strPath
        Me.imgPDF.Action = acOLECreateLink
       
        ' If got an error,
        If Err <> 0 Then
            ' Then set the message
            Me.lblMsg.Caption = "Photo not found.  Click Add to correct."
            ' Make it visible
            Me.lblMsg.Visible = True
            ' .. and hide the image frame
            Me.imgPDF.Visible = False
        Else
            ' Reveal the picture
            Me.imgPDF.Visible = True
            ' And set the form palette so the picture displays correctly
            Me.PaintPalette = Me.imgPDF.ObjectPalette
        End If
    End If
   
End Sub
 
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 note PDF File"
        ' Set the default directory
        .Directory = CurrentProject.Path & "\Pictures\"
        ' .. and file extension
        .Extension = "pdf"
        ' .. but show all graphics files just in case
        '.Filter = "Image Files (.bmp, .jpg, .gif, .pdf)|*.bmp;*.jpg;*.gif;*.pdf"
        .Filter = "PDF Files (.pdf)|*.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.imgPDF.Picture = strPath
        Me.imgPDF.SourceDoc = strPath
        Me.imgPDF.Action = acOLECreateLink
        ' 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.imgPDF.Visible = True
        Else
            ' OOOps.
            ' Clear photo
            Me.txtPhoto = Null
            ' Hide the frame
            Me.imgPDF.Visible = False
            ' Clear the image
            Me.imgPDF.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




With Warm Regards,
 
Arthur D. Lorenzini
IT System Manager
Cheyenne River Housing Authority
Wk.(605)964-4265  Ext. 130
Fax (605)964-1070
"Only those who will risk going too far can possibly find out how far one can go."






On Friday, May 30, 2014 9:08 AM, "John Viescas JohnV@msn.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com> wrote:


 
My bad - I didn't notice it's a PDF.

Art-  You need a Text field to store the link outside of the OLEBound control.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On May 30, 2014, at 3:55 PM, wrmosca@comcast.net [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

John & Art

Unless I'm mistaken, you have to use an OLEObject control, not an image control to show a PDF. And I was not saying to store a link. The path is still stored as a text. I simply took your sample for showing images and made a couple small changes: the control and a couple lines of code.

When changing the SourceDoc on an OLEBound control you also have to set the action. That's where Me.OLEBound4.Action = acOLECreateLink comes into play. That link is not stored. It is done to create a link to the file for the control's use only.

Art - I'm not sure why the code jumps to the Else line. Comment out the "On Error Resume Next" so you can see the error line.


Bill


---In MS_Access_Professionals@yahoogroups.com, <JohnV@msn.com> wrote :

Art-

Not sure why Bill recommended you continue to store a link to the image in the database in an OLEObject.  As of Access 2007, all you need is a Text field to store the full path.  Use an Image control on forms and reports and set the Control Source of the Image control to the text field.  Access will load the image for you for each record.  You still need a bit of code to invoke the file dialog when the user wants to locate and save a new image.

Note that if this is a shared network app, the path must use an UNC path, not a drive letter.  You can help ensure that happens by setting the starting .Directory to the network path and folder, sort of like:

    .Directory = "\\OurShare\Photos\"

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On May 30, 2014, at 12:32 AM, Art Lorenzini dbalorenzini@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:

This is the add code

 ' 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 note PDF File"
        ' Set the default directory
        .Directory = CurrentProject.Path & "\Pictures\"
        ' .. and file extension
        .Extension = "pdf"
        ' .. but show all graphics files just in case
        '.Filter = "Image Files (.bmp, .jpg, .gif, .pdf)|*.bmp;*.jpg;*.gif;*.pdf"
        .Filter = "PDF Files (.pdf)|*.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.imgPDF.SourceDoc = strPath
        Me.imgPDF.Action = acOLECreateLink
        ' 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.imgPDF.Visible = True
        Else
            ' OOOps.
            ' Clear photo
            Me.txtPhoto = Null
            ' Hide the frame
            Me.imgPDF.Visible = False
            ' Clear the image
            Me.imgPDF.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


I stepped through it and drops right to the Else statement. I Changed the name of the control from imgPhoto to imgPDF.
 

With Warm Regards,
 
Arthur D. Lorenzini
IT System Manager
Cheyenne River Housing Authority
Wk.(605)964-4265  Ext. 130
Fax (605)964-1070
"Only those who will risk going too far can possibly find out how far one can go."






On , Art Lorenzini <dbalorenzini@yahoo.com> wrote:


I have made the changes but for some reason it is not saving the path so I have to locate the PDF file each time I open the record.
 

With Warm Regards,
 
Arthur D. Lorenzini
IT System Manager
Cheyenne River Housing Authority
Wk.(605)964-4265  Ext. 130
Fax (605)964-1070
"Only those who will risk going too far can possibly find out how far one can go."






On Thursday, May 29, 2014 3:48 PM, "wrmosca@comcast.net [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com> wrote:


 
Art - replace the image control with an OLEBound control. Keep the same name so you have less work to do.

Change this line where ever it exists:
Me.imgMember.Picture = strPath

to this:
Me.OLEBound1.SourceDoc = strPath
Me.OLEBound1.Action = acOLECreateLink

Also, if you are using a common dialog to get the path, change the filter/extension to PDF

    With New ComDlg
        ' Don't allow multiple files
        .AllowMultiSelect = False
        ' Set the title of the dialog
        .DialogTitle = "Locate Member picture File"
        ' Set the default directory
        .Directory = CurrentProject.Path & "\Pictures\"
        ' .. and file extension
        .Extension = "pdf"
        ' .. but show all PDF files just in case
        .Filter = "PDF Files (.pdf)|*.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


Regards,
Bill Mosca


From: "Art Lorenzini dbalorenzini@yahoo.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com>
To: "MS Access Professionals" <MS_Access_Professionals@yahoogroups.com>
Sent: Thursday, May 29, 2014 11:06:31 AM
Subject: Re: [MS_AccessPros] Re: Working with PDFS in Access 2013

 
Bill,
I am sorry but I don't even know where to begin with that. I have attached a screen shot of what it looks like right now. Like this is based off images and not PDF files.

With Warm Regards,

Arthur D. Lorenzini
IT System Manager
Cheyenne River Housing Authority
Wk.(605)964-4265  Ext. 130
Fax (605)964-1070
alorenzini@crhanetwork.org
"Only those who will risk going too far can possibly find out how far one can go."

On Thursday, May 29, 2014 12:40 PM, "wrmosca@comcast.net [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com> wrote:


 
Art
Use a bound OLE control.

Private Sub Command1_Click()
    Me.OLEBound4.SourceDoc = "C:\MyFolder\MyPDFfile.pdf"
    Me.OLEBound4.Action = acOLECreateLink
    
End Sub

-Bill

[Non-text portions of this message have been removed]











__._,_.___

Posted by: Art Lorenzini <dbalorenzini@yahoo.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (15)

.

__,_._,___

Tidak ada komentar:

Posting Komentar