Page 1 of 2 12 LastLast
Results 1 to 15 of 30
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PDF Control (VB6)

    Some time ago, I created a facility within Access to view PDF files from a default location and with a pre-determined prefix of 5 numbers, ie
    15489.pdf etc etc.

    I'm having a dabble at re-creating this facility in VB so it can be distributed as an EXE.
    With Access, using the more tools menu, there are Acrobat addins to insert into the form.

    Are there, or is there the same facility with VB.
    I've created a form and inserted an OLE control from the left menu which only shows the PDF as an icon and needs
    to be double clicked to show the PDF.

    Is this the correct control to use and which properties will achieve what I need to do, or do I need a separate control.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: PDF Control (VB6)

    Which control are you using? Acrobat.ocx seems to work OK.

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF Control (VB6)

    Hans
    I think I found it, Right click the standard VB tools to edit the components menu.
    "Acrobat Control for ActiveX" ??

    I'll have to get used to the differences with VB as opposed to VBA

    Thanks anyway.

  4. #4
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF Control (VB6)

    Ok here's the first problem.
    If I set the forms load event to populate a string value into an unbound text called AcrobatPath:

    Me.AcrobatPath = "L:MMPDFBIS.pdf"
    Me.ctlAcrobat.src = Me.AcrobatPath

    The pdf doc loads ok.

    I have a
    DriveListBox - Drive1
    DirListBox - Dir1
    FileListBox - File1

    If I use their Change events:

    Private Sub Dir1_Change()
    File1 = Dir1
    End Sub

    Private Sub Drive1_Change()
    Dir1 = Drive1
    End Sub

    Private Sub File1_Click()
    FN = Dir1
    Me.AcrobatPath = File1
    Me.ctlAcrobat.src = Me.AcrobatPath
    End Sub

    The ctlAcrobat doesn't show the PDF when selecting a pdf from the File1 FileListBox
    The control just goes white.
    Do I need to requery or refresh in some way ?

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF Control (VB6)

    Got it:

    Private Sub File1_Click()
    FN = Dir1
    Me.AcrobatPath = Dir1 & "" & File1
    Me.ctlAcrobat.src = Me.AcrobatPath
    End Sub

    But any other advice is welcome.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: PDF Control (VB6)

    One remark: the DriveListBox, DirListBox and FileListBox are remnants from Windows 3.x. Although they work fine, most applications use the standard Open dialog. This is contained in the Microsoft Common Dialog Control 6.0. Right-click the Toolbox and select Components... to add it to the Toolbox.

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF Control (VB6)

    Hans
    Yes the three controls look somewhat bulky and the DirListBox has to be resized to see any kind of effect.
    I'll look at the common Dialog now.
    Thanks

  8. #8
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF Control (VB6)

    Hans
    The dialog shows on the forms design, but when the form is run, it is invisible.
    I obviously need to reference it in code some-how ?

    Told you I'd get my feet wet.
    Any pointers would be helpful.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: PDF Control (VB6)

    See Displaying Open and Save As Dialog Boxes.

    BTW, you can also copy the Windows API code you use in Access into a VB6 module! The only thing that has to change is hwndAccessApp. Replace that with Me.hWnd.

  10. #10
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF Control (VB6)

    Hans
    Cheers for the link, that makes things clearer and there's plenty for me to look at there.

  11. #11
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF Control (VB6)

    Hans
    Using the example from Microsoft, the Dialog is opening ok and filtering all the PDF's from the correct folder.
    The example from Microsoft doesn't show any reference to the "OpenFile" procedure:

    ' Call the open file procedure.
    OpenFile (cmnDialog.FileName)

    I'm not sure whether my modListPDFs from Access will do the same job:

    <pre>Function ListPDFs(fld As Control, ID As Variant, _
    row As Variant, col As Variant, _
    Code As Variant) As Variant
    Static dbs(127) As String, Entries As Integer
    Dim ReturnVal As Variant
    ReturnVal = Null
    Select Case Code
    Case acLBInitialize ' Initialize.
    Entries = 0
    dbs(Entries) = Dir("L:MMPDF*.PDF")

    Do Until dbs(Entries) = "" Or Entries >= 127
    Entries = Entries + 1
    dbs(Entries) = Dir
    Loop
    ReturnVal = Entries
    Case acLBOpen ' Open.
    ' Generate unique ID for control.
    ReturnVal = Timer
    Case acLBGetRowCount ' Get number of rows.
    ReturnVal = Entries
    Case acLBGetColumnCount ' Get number of columns.
    ReturnVal = 1
    Case acLBGetColumnWidth ' Column width.
    ' -1 forces use of default width.
    ReturnVal = -1
    Case acLBGetValue ' Get data.
    ReturnVal = dbs(row)
    Case acLBEnd ' End.
    Erase dbs
    End Select
    ListPDFs = ReturnVal
    End Function</pre>


  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: PDF Control (VB6)

    The ListPDF function in your post is a callback function for an Access list box. As far as I know, there is no equivalent for this in VB6, so you can't use it here.

    The example in the MSDN library is generic. The OpenFile procedure represents a user-defined routine that opens the file in the application; it is not specified further. The idea is that the Common Dialog Control returns the name of the file selected by the user in the the FileName property. It is up to you as programmer to do something with it, in this case to set the src property of the Acrobat control to this file name:

    Me.AcrobatPath = cmnDialog.FileName
    Me.ctlAcrobat.src = Me.AcrobatPath

  13. #13
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF Control (VB6)

    I think this is where I went wrong, I tried:

    Me.AcrobatPath = (cmnDialog.FileName)
    Me.ctlAcrobat.src = Me.AcrobatPath

    Instead of :

    Me.AcrobatPath = cmnDialog.FileName
    Me.ctlAcrobat.src = Me.AcrobatPath

    Simple errors eh !!

    Thanks again.

  14. #14
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: PDF Control (VB6)

    Ok Hans
    I've got this working so selecting the Dialog will pull the selected PDF.
    I'm working on pulling all PDF's which have a prefix Left,5 characters.
    I've placed a text on the form and changed it's properties to "Number"
    And taken the following code from my working Access form.
    It doesn't work or give me any error msg's
    Is there something obvious in the code I should be looking at ?
    The strPDF5 works ok because I can find the value when the button is clicked simply by using
    MsgBox strPDF5 which returns any thing in the text box.
    I'm not sure if the strFolder in the decalarations is correct ?


    <pre>Option Explicit

    Private strFolder As String
    Private strExtension As String
    Private arrFileNames(1 To 127) As String
    Private intFileCount As Integer
    Private intCurIndex As Integer
    Private intNumberOfPDFs As Integer
    Private Const MaxNumberOfPdfs = 1

    Private Sub FillPDFS(intIndex As Integer)
    On Error GoTo ErrHandler
    Dim I As Integer
    If intIndex > intFileCount - intNumberOfPDFs + 1 Then
    intIndex = intFileCount - intNumberOfPDFs + 1
    End If
    If intIndex < 1 Then
    intIndex = 1
    End If
    For I = 1 To intNumberOfPDFs
    Me.ctlAcrobat.src = strFolder & "" & arrFileNames(I + intIndex - 1)
    Next
    Me.txtInfo = "PDFS " & intIndex & " to " & (intIndex + intNumberOfPDFs - 1) & " of " & intFileCount
    intCurIndex = intIndex

    'Me.cmdFirst.Enabled = (intIndex > 1)
    'Me.cmdPrev.Enabled = (intIndex > 1)
    'Me.cmdNext.Enabled = (intIndex < intFileCount)
    'Me.cmdLast.Enabled = (intIndex < intFileCount - intNumberOfPDFs)
    'DoCmd.Hourglass False
    Exit Sub
    ErrHandler:
    MsgBox Err.Description, vbExclamation
    End Sub
    Private Sub Command1_Click()
    On Error GoTo ErrHandler
    Dim I As Integer
    Dim strFile As String
    ' strPDF5 to find left most 5 characters for frmDetails
    Dim strPDF5 As String

    ' Fixed folder
    strFolder = "L:MMPDF-VBEstPDF-VB"

    ' Get Left5
    strPDF5 = Left(Me.txtEst, 5)

    I = 0
    ' Get PDF files in strFolder whose names begin with strPDF5
    strFile = Dir(strFolder & "" & strPDF5 & "*.pdf")

    ' Loop through files
    Do While strFile <> "" And I < 127
    I = I + 1
    arrFileNames(I) = strFile
    strFile = Dir
    Loop
    intFileCount = I
    If intFileCount < MaxNumberOfPdfs Then
    intNumberOfPDFs = intFileCount
    Else
    intNumberOfPDFs = MaxNumberOfPdfs
    End If
    If intNumberOfPDFs = 0 Then
    Else

    End If
    Exit Sub
    ErrHandler:
    MsgBox Err.Description, vbExclamation
    End Sub</pre>


  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: PDF Control (VB6)

    I don't understand what you want to do with the FillPDFs procedure. It sets the source of the acrobat control to each of a series of PDF files in turn. What is that going to accomplish?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •