|
-
Aug 20th, 2008, 03:18 PM
#1
Thread Starter
PowerPoster
[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
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]
-
Aug 20th, 2008, 03:46 PM
#2
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.
-
Aug 20th, 2008, 04:34 PM
#3
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
-
Aug 20th, 2008, 06:45 PM
#4
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 "*")
-
Aug 21st, 2008, 07:17 AM
#5
Thread Starter
PowerPoster
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]
-
Aug 21st, 2008, 07:32 AM
#6
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
-
Aug 21st, 2008, 07:56 AM
#7
Thread Starter
PowerPoster
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]
-
Aug 21st, 2008, 09:48 AM
#8
Thread Starter
PowerPoster
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]
-
Aug 21st, 2008, 04:30 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|