Results 1 to 9 of 9

Thread: [RESOLVED] Print question

  1. #1

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Resolved [RESOLVED] Print question

    In line with my last question...

    I have this code that looks at my inventory. If the item is active, it looks for a PDF file that starts with that product number. That works. However, if it finds the PDF, I need to be able to print it.

    My code that works :
    Code:
    Dim msg As String
    msg = ""
    
    Dim foundit As String
    Dim name As String
    '==============================
    Set rs1 = New ADODB.Recordset
    '==============================
    sql = "SELECT * FROM PRINTED WHERE LTRIM(RTRIM([CUST])) = " & "'" & "TRIA" & "'"
    sql = sql & " ORDER BY [PRTD]"
    rs1.Open sql, CnxnTechSQL, adOpenKeyset, adLockReadOnly, adCmdText
    If Not rs1.BOF And Not rs1.EOF Then
        rs1.MoveFirst
        Do
            If rs1![actinact] = "A" Then
                name = "Z:\Junior\PDF\" & rs1![prtd] & "*.PDF"
                foundit = Dir(name)
                If foundit <> "" Then
                    MsgBox name
                Else
                    msg = msg & rs1![prtd] & vbCrLf
                End If
            End If
            rs1.MoveNext
        Loop While Not rs1.EOF
    End If
    rs1.Close
    Set rs1 = Nothing
    '=================
    
    
    MsgBox "DONE" & vbCrLf & msg
    There is some extra code for testing purposes right now.

    When this is executed
    Code:
    MsgBox name
    I get something like "Z:\Junior\PDF\1234567*.PDF"

    What I want to see is the file's name, such as
    "Z:\Junior\PDF\1234567 Brand new hair Conditioner 25 oz.PDF"

    Maybe I don't need that. What I need to do, instead of the msgbox is to print the PDF file. Without the filename, how can I do that?
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  2. #2
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Print question

    To print a file anyhow you need to get the full file name....
    how do you find that this 1234567 is linked with a specific file name...do you have any database to fetch this details....

    after finding the file name, I guess you can use ShellExecute to print the file....
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Print question

    you should use shellexecute with "Print" to print the file in the default pdf reading program
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Print question

    Hope this help: (You need to declare ShellExecute API function as westconn1 mentioned)
    Code:
        Const PDFPath = "Z:\Junior\PDF"
        Dim Filename As String
        '... ...
        
            If rs1![actinact] = "A" Then
                Filename = Dir(PDFPath & "\" & rs1![prtd] & "*.PDF")
                If Filename <> "" Then
                    MsgBox "This file will be printed: " & PDFPath & "\" & Filename
                    ShellExecute 0, "print", Filename, "", PDFPath, 1
                Else
                    msg = msg & rs1![prtd] & vbCrLf
                End If
            End If
        '... ...
    In your code, the actual filename is the variable [foundit] (if not blank) while the variable [name] holds the file pattern and it is not a valid filename (contains "*")
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  5. #5

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Print question

    I'm very close. This code will display the PDF file using Adobe Reader.

    Code:
    Dim msg As String
    msg = ""
    
    '==============================
    Set rs1 = New ADODB.Recordset
    '==============================
    sql = "SELECT * FROM PRINTED WHERE LTRIM(RTRIM([CUST])) = " & "'" & "TRIA" & "'"
    sql = sql & " ORDER BY [PRTD]"
    rs1.Open sql, CnxnTechSQL, adOpenKeyset, adLockReadOnly, adCmdText
    If Not rs1.BOF And Not rs1.EOF Then
        rs1.MoveFirst
        Dim FNAME As String
        Dim PDF As String
        Do
            If rs1![actinact] = "A" Then
                FNAME = "Z:\JUNIOR\PDF\" & rs1![prtd]
                PDF = Dir(FNAME & "*.PDF")
                If PDF <> "" Then
                    Call Shell("C:\Program Files\Adobe\Reader 8.0\Reader\ACRORD32.EXE " & FNAME & "*", vbNormalFocus)
                Else
                    msg = msg & rs1![prtd] & vbCrLf
                End If
            End If
            rs1.MoveNext
        Loop While Not rs1.EOF
    End If
    rs1.Close
    Set rs1 = Nothing
    '=================
    
    
    MsgBox "DONE" & vbCrLf & msg
    Now, to get it to print automatically...
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Print question

    possibly /p at the end of the shell string
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Print question

    OK. I installed Acrobat pro (Reader can't print). The code now:
    Code:
            If rs1![actinact] = "A" Then
                Fname = "Z:\JUNIOR\PDF\" & rs1![prtd]
                PDF = Dir(Fname & "*.PDF")
                If PDF <> "" Then
                    Call Shell("C:\Program Files\Adobe\Acrobat 8.0\Acrobat\Acrobat.EXE/p " & Fname & "*", vbNormalFocus)
                Else
                    msg = msg & rs1![prtd] & vbCrLf
                End If
            End If
    I think this might work. However, I get a "file not found" error. This takes me back to the start. How do I get the ENTIRE file name to use in the variable?
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  8. #8

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Print question

    I am marking this thread as resolved because I can't spend any more time on it. There are only 113 files in question. I am writing their partial names to a text file and just printing them manually.

    Thanks for all the replies, though.
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [RESOLVED] Print question

    file name strings passed to the shell as an argument can not have any spaces in them unless the entire file name string is enclosed in quotes
    one reason why shell execute is a better option

    to enclose string in quotes
    fname = """" & fname & """"
    where fname is a file name /path
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width