UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
3 Pages V < 1 2 3 >  (Go to first unread post)
   Reply to this topicStart new topic
> Printing Pdf's From Access    
 
   
jleach
post May 27 2011, 03:54 PM
Post#21


UtterAccess Editor
Posts: 9,899
Joined: 7-December 09
From: Staten Island, NY, USA


Just out of curiousity, have you checked the spool status? Printers, IME, do have a tendancy to be extremely lazy, especially when confronted with large amounts of work to do. I'm curious if the print command is just not going or possibly getting hung up with the spool service.
Go to the top of the page
 
caosity
post May 27 2011, 04:41 PM
Post#22



Posts: 16
Joined: 26-May 11



Doug,
othing changed, it still will not print, but marks the files as printed. Also, my table has 5 fields ID, Field1, Field2, path, and print_flag. The data in the table may be as follows:
ID------------Field1-------------Field2-------------path------------print_flag
1--------------text here---------filename.pdf-----C:\Print\-------true/false
I have also tried putting something like C:\Print\filename.pdf in the path field, still nothing.
JLeach, I checked the service, also stopped it and restarted it. Nothing.
Utterly confused. What am I doing wrong?
Go to the top of the page
 
jleach
post May 27 2011, 05:33 PM
Post#23


UtterAccess Editor
Posts: 9,899
Joined: 7-December 09
From: Staten Island, NY, USA


Try putting this in each loop iteration:
!--c1-->
CODE
DoEvents: DoEvents: DoEvents

This gives VBA a breather and lets the system catch up with other pending tasks. Doing it three times is like clicking a reset button - sometimes once or twice just isn't enough. These should run between each call to the printing function. I'll often use them when handling file processing or the like.
Another (longer) alternative, if this cannot be gotten to the bottom of, may be to merge all of the required pdf files into one temp pdf and print the one file. I've always found that printers have a tendency to curl up and die if you give them too many jobs to que at once, and the numbers you're talking are far beyond what I've worked with (pagewise not really, object-wise yes). But maybe you do this somewhere else besides Access and don't have any problems - I don't claim to be a printer guru by any means.
If you want to try the merge pdf route it's relatively simple and can be done for free. Let me know. I'd still be curious if DoEvents worked. You said if you print just one file by typing the code manually it works? And the spooler doesn't have any jobs at all queued after you run the loop?
Go to the top of the page
 
caosity
post May 28 2011, 07:16 AM
Post#24



Posts: 16
Joined: 26-May 11



JLeach,
bit of background. I work in an environment where we often get thousands of pdfs to print from multiple companies. Now, for the most part, these companies send the pdf's merged, like you talk about, which we print and then must alphabetize, which is annoying. But recently we started working with a company that does not. In addition to the pdfs, we get an excel spreadsheet listing the documents, which will be imported into Access. These documents are named with client names and id numbers, which are also contained in the spreadsheet. The documents that are in the folder are in order by first names as that is how the company names them, and they can't change that, I've asked. We just got a batch of documents in, 1574, this is not uncommon and will continue in the future. Merging that many pdfs into one really isn't an option as each document may be 6-10 pages.
My goal is to import the spreadsheet into Access, sort the table by last name, this table will also have the full filename and path, and have Access go through and print each one.
On a side note, we print to a large Xerox printer that does handle this, but we are just about on a first name basis with the repair/maintenance guy. It is not uncommon for us to print anywhere from 100,000 to 500,000 pages a month.
HAs I understand it, the DoEvents: is just a timing issue. I still don't have it printing. Any help anyone can provide with the printing issue would be greatly appreciated.
Go to the top of the page
 
niesz
post May 28 2011, 07:52 AM
Post#25


Utter A-fishin'-ado
Posts: 17,958
Joined: 1-August 05
From: Cincinnati, Ohio, USA . . . ><((((°>


Have you placed code stops on the print line to make sure your code is executing? That's the best way to tell what's going on.
tep through the code line by line as it's executing to make sure all of your logic is working as expected.
Go to the top of the page
 
Doug Steele
post May 28 2011, 07:59 AM
Post#26


UtterAccess VIP
Posts: 21,732
Joined: 8-January 07
From: St. Catharines, ON (Canada)


In order to print, you need to give it the path and filename: given the new information you've given, you're actually only giving it the path.
hange
CODE
  myLOGPRNTpath = rsLOGPRNT![Path]

to
CODE
  myLOGPRNTpath = rsLOGPRNT![Path] & rsLOGPRNT![Field2]

Change
CODE
  mysql = "update [Print] set [Print].print_flag = -1 where Print.path = """ & myLOGPRNTpath & """;"

to
CODE
  mysql = "UPDATE [Print] SET [Print].print_flag = -1 " & _
    "WHERE Path = """ & rsLOGPRNT![Path] & """ " & _
    "AND Field2 = """ & rsLOGPRNT![Field2] & """;"
Go to the top of the page
 
caosity
post May 28 2011, 12:31 PM
Post#27



Posts: 16
Joined: 26-May 11



Doug,
This makes sense, and I have changed my code as you stated. Below is my current code:
Option Compare Database
Function TP()
Dim hwndret As Long
Dim dbcurr As DAO.Database
Dim rsLOGPRNT As DAO.Recordset ' rs is recordset and table name
Dim myLOGPRNTpath As Variant 'path name for document to print
Dim myprint As Variant 'dim created to capture when print check box is checked
Dim mycurrentbase As Variant
Dim mypreviousbase As Variant
Dim mysql As String 'sets print_flag to checked after command to print is sent
Dim strSQL As String

Set dbcurr = CurrentDb()
strSQL = "Select * From Print " & _
"ORDER BY Print.Field2;"
Set rsLOGPRNT = dbcurr.OpenRecordset(strSQL)
mypreviousbase = rsLOGPRNT![Field2]
Do While Not rsLOGPRNT.EOF
myLOGPRNTpath = rsLOGPRNT![Path] & rsLOGPRNT![Field2]
myprint = rsLOGPRNT![print_flag]
mycurrentbase = rsLOGPRNT![Field2]
If myprint = False Then
CreateObject("Shell.Application").Namespace(0).ParseName(myLOGPRNTpath).InvokeVerb ("Print")
mysql = "UPDATE [Print] SET [Print].print_flag = -1 " & _
"WHERE Path = """ & rsLOGPRNT![Path] & """ " & _
"AND Field2 = """ & rsLOGPRNT![Field2] & """;"
' Debug.Print mysql
dbcurr.Execute mysql, dbFailOnError
End If
rsLOGPRNT.MoveNext
Loop

rsLOGPRNT.Close
Set rsLOGPRNT = Nothing

End Function
I have also installed FoxIt Reader and made it my default reader for PDF documents. Now when I run the code, it runs through, marks my documents as printed, and prints some. But I get a run time error 91, Object variable or With block variable not set. How do I handle this one?
We are getting closer and I very much appreciate your help.
Go to the top of the page
 
Doug Steele
post May 28 2011, 01:45 PM
Post#28


UtterAccess VIP
Posts: 21,732
Joined: 8-January 07
From: St. Catharines, ON (Canada)


Well, since I've never tried Albert's approach to printing, I'm not going to try and debug it. Let's go back to the ShellWait approach. I'm also going to remove variables from your code that you're not using, and remove the Update statement, since as you'll see, there's an easier way to mark them as printed.
!--c1-->
CODE
Function TP()
Dim dbcurr As DAO.Database
Dim rsLOGPRNT As DAO.Recordset ' rs is recordset and table name
Dim strCommand As String
Dim strSQL As String
  
  Set dbcurr = CurrentDb()
  strSQL = "Select * From Print " & _
    "ORDER BY Print.Field2;"
  Set rsLOGPRNT = dbcurr.OpenRecordset(strSQL)
  Do While Not rsLOGPRNT.EOF
    If rsLOGPRNT![print_flag] = False Then
      strCommand = """C:\Program Files\Foxit Software\Foxit Reader\FoxitReader.exe""" & _
        " -p """ & rsLOGPRNT![Path] & rsLOGPRNT![Field2] & """"
'      Debug.Print strCommand
      ShellWait strCommand
      rsLOGPRNT.Edit
      rsLOGPRNT![Print_flag] = True
      rsLOGPRNT.Update
    End If
    rsLOGPRNT.MoveNext
  Loop
  
  rsLOGPRNT.Close
  Set rsLOGPRNT = Nothing
  
End Function

If that still doesn't work, then remove the comment symbol from in front of Debug.Print strCommand. Copy the command string that's printed in the Debug window and paste it into a DOS Command window to see whether it works.
Go to the top of the page
 
caosity
post May 28 2011, 02:11 PM
Post#29



Posts: 16
Joined: 26-May 11



ok, found the problem, took care of it, I deleted the" Set rsLOGPRNT = Nothing" line, this seems to allow it to print all of my documents. Now my only concern is that it does not print in the order they appear in my table.
If this is the worst of my problems, I think I will be ok.
If anyone can help me with code to print in the order of the table, I would be grateful. Otherwise, THANK YOU to everyone that helped me. You went above and beyond.
My final code is:
Option Compare Database
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Function TP()
Dim dbcurr As DAO.Database
Dim rsLOGPRNT As DAO.Recordset ' rs is recordset and table name
Dim myLOGPRNTpath As Variant 'path name for document to print
Dim myprint As Variant 'dim created to capture when print check box is checked
Dim mycurrentbase As Variant
Dim mypreviousbase As Variant
Dim mysql As String 'sets print_flag to checked after command to print is sent
Dim strSQL As String

Set dbcurr = CurrentDb()
strSQL = "Select * From Print " & _
"ORDER BY Print.Field2;"
Set rsLOGPRNT = dbcurr.OpenRecordset(strSQL)
mypreviousbase = rsLOGPRNT![Field2]
Do While Not rsLOGPRNT.EOF
myLOGPRNTpath = rsLOGPRNT![Path] & rsLOGPRNT![Field2]
myprint = rsLOGPRNT![Print_flag]
mycurrentbase = rsLOGPRNT![Field2]
If myprint = False Then
CreateObject("Shell.Application").Namespace(0).ParseName(myLOGPRNTpath).InvokeVerb ("Print")
mysql = "UPDATE [Print] SET [Print].print_flag = -1 " & _
"WHERE Path = """ & rsLOGPRNT![Path] & """ " & _
"AND Field2 = """ & rsLOGPRNT![Field2] & """;"
' Debug.Print mysql
dbcurr.Execute mysql, dbFailOnError
End If
rsLOGPRNT.MoveNext
Sleep (2000) 'Sleep for 2 seconds
Loop

rsLOGPRNT.Close

End Function

Oadded the sleep function to make sure I didn't overload the printer, or spooler whichever, so I would not lose any documents. This may make my print job last 2 hours, but with a spare computer on a spare desk, and all of my documents (not yet tested), I think I can live with that.
Go to the top of the page
 
Doug Steele
post May 28 2011, 04:47 PM
Post#30


UtterAccess VIP
Posts: 21,732
Joined: 8-January 07
From: St. Catharines, ON (Canada)


NEVER assume that records in tables have an order: they don't. Think of tables as "sacks of data". The records may be presented in a specific order, but Access actually fits them in the table wherever it feels like. If the order matters, then you have to figure out a way to create a query that has an ORDER BY clause that sorts the records appropriately. If you don't, Access could very well reorder the records the next time you compact the database. The SQL statement you're using includes ORDER BY Print.Field2, so that's the order in which they're returned. You really should use more meaningful names! And on the topic of names, you really should rename your table. Print is a reserved word, and you should never use reserved words for your own purposes! For a comprehensive list of names to avoid (as well as a link for a free utility to check your applciation for compliance), see what Allen Browne has at Problem names and reserved words in Access
WIW, there's no possible way that removing the Set rsLOGPRNT = Nothing statement from the end of the routine could make your code suddenly work. Something else must have changed at the same time. The recordset is already closed at the point in the routine where you have that statement: setting the variable to Nothing just removes the reference between the variable and the (closed) recordset.
Go to the top of the page
 
AlbertKallal
post May 29 2011, 12:48 AM
Post#31


UtterAccess VIP
Posts: 2,617
Joined: 12-April 07
From: Edmonton, Alberta Canada


Good to see that simple one line of code works just fine. As noted, it works for word, excel and many other windows programs (so that one line of code can print most documents).
Yto see that simple one line of code works just fine. As noted, it works for word, excel and many other windows programs (so that one line of code can print most documents).
Your next problem of order can indeed be difficult to solve. While you can set the order of the table by using a query, the print spooler in windows is another matter. If there ever was one weak area in windows in terms of business applications it would be the print spooler IMHO.
Having come from several systems where we did tons of batch processing, the settings of the printer spooling system from code was oh so very important on these systems. Typical approach would be
"start new spool job"
"force spool job stay open"
"output + print several documents from several different programs"
"close spool job"
"print spool job"
In effect the above steps would allow one to "assemble" a set of documents that often come from SEVERAL different programs. Often a typical office task revolves around several programs such as word (cover letter), Excel (rates or calculations) and some type of database system or output from an Accounting system (or billing/quote system).
We REALLY need this ability in windows.
And today, what is worse is now with dual processor systems and new threading issues, you cannot really be sure that the word document you are printing to the spooler will get out first before the excel sheet and pdf document you also attempting to print in this supposed "document set".
The problem of course is often a few documents out of order in a print job can have absolute disastrous effects. I was involved in a system in which several different documents were produced from several different programs that had to be run one after another. It was critical that the output of these documents assemble in correct order.
These documents were in fact medical diagnosis of patients, and a few sheets placed in wrong order of a batch run would in fact mean that one patient could be incorrectly told that they have cancer, while another patient would be incorrectly told they do not. Now not all applications have such serious results when print order is messed up, but even in situations like sending out the wrong page of an invoice or bill to a customer can have significant effects on customer goodwill. No customer likes the wrong billing totals, especially when NOT in their favor. And even sheets of shipping order messed up in a pile of papers for the shipping room not only results in unhappy customers but one now has to deal with nasty shipping costs. Both customers are mad, and now BOTH must return goods and you again must ship to BOTH customers again - what a mess!
Beyond billing and shipping, even an insurance quote system where we use a word template, some excel documents and perhaps some insurance policy pulled from a custom insurance database will then needs assembly into one nice package. Again any out of order printing can often make the job very difficult for people that remove this output from the printers and package up and ship out that material to customers all day long.
Ospent a little bit of time to mention and share the above issues, since for many business applications the developers often give little thought as to how such a small issue as printing a few little silly documents out of order can have serious business issues.
In the case of the medical clinic, discovery of that mistake cost several days of time since all of the staff had be called in for the whole weekend to go through every single diagnosis and document that had been sent out in the last couple of days to verify that patients had not been incorrectly informed. This huge mess and massive amount of labor cost was due to a little silly print spooling issue that caused some documents to be printed out of order.
HAs noted so often many jobs are based around a set of documents. For that insurance claim, you have an envelope and cover letter is printed from word (some custom text needed to be entered and edited by the person building this claim). Then perhaps a spreadsheet that has certain rates to help with claims calculations comes from Excel. And then the additional information on policy terms comes from a database report and insurance reporting system you built in Access. All these documents must then be sent out to the customer. And of course the summer student hired to take the output from the 4 laser printers that you're running at full blast all day with all these documents constantly coming out means any pile out of order becomes very difficult for the person taking that output and documents.
So, the lesson and the moral story here is developers often fail to realize how important order and assembly of documents is.
In fact if you're going to setup output order here, I would probably suggest that you come up some type of numbering system for the PDF documents. You THEN AFTER outputting the documents with some type of number system, you next run some code to take all of those documents and assemble them into one single PDF document, and then print that (that way the pages and material inside is guaranteed to be in your correct order).
As a side note, a system that allows you to use com object automation, and pull documents together and assemble them into one then print or create a new PF document is the free open source library here:
http://www.pdfforge.org/
Note that after you install the above PDFcreator system, there are some REALLY nice
windows scripts (vbs, and suitable for VBA) that have examples on how to assemble documents together. These sample scripts are installed in some sub folders of the program dir used during installation.
So just keep in mind in any system where you send multiple print jobs to the print spooler, the print spooler settings will not ensure that all the documents print in that particular order. The only solution is to have some system in which the print spooler can remain open during this whole assembly and output process or you output all of separate documents into some type of directory with an numbering system. You then run additional code to assemble those numbered documents into one single print job.
And of course if you can setup ALL OF the above to occur in one report run from inside of access, then you eliminate the multiple document assembly problem. So it's often worth it to put a lot of extra hard work to cook up a way to produce all output in one report. Often sometimes we developers are a bit lazy, and often we send off multiple reports when some type of report grouping would suffice.
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
kallal@msn.com
Go to the top of the page
 
jleach
post May 29 2011, 12:58 AM
Post#32


UtterAccess Editor
Posts: 9,899
Joined: 7-December 09
From: Staten Island, NY, USA


Excellent writeup Albert. I'd love to convert this to a wiki topic of you wouldn&
Go to the top of the page
 
AlbertKallal
post May 29 2011, 02:27 AM
Post#33


UtterAccess VIP
Posts: 2,617
Joined: 12-April 07
From: Edmonton, Alberta Canada


Thank you kindly for the comments.
And I have no problem you taking this and making a wiki article out of this.
Oenjoyed sharing the above experience with the great bunch of people here at UA.
And I dare say that such an out of order printing issue is not restricted to medical centers with such obvious liability issues.
Small mom and pop operations sending out invoices that are mixed up between two different customers during a print job are not only embarrassing but can result in detrimental consequences to their business bottom line.
At the end of the day, I think we're talking about the difference between writing code for a computer to maintain order of output and that of consulting to clients the consequences of such actions.
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
kallal@msn.com
Go to the top of the page
 
jleach
post May 29 2011, 08:21 AM
Post#34


UtterAccess Editor
Posts: 9,899
Joined: 7-December 09
From: Staten Island, NY, USA


The slightly modified writeup can be found in the wiki under the following headings:
Document Assemblies (main article)
Batch Printing (redirect to Document Assemblies)
Printing Multiple Files In Order (Redirect to Document Assemblies)
Thanks Albert
Go to the top of the page
 
caosity
post May 31 2011, 09:48 AM
Post#35



Posts: 16
Joined: 26-May 11



Doug, Albert,
Sorry for the delay in responding, I was out for the holiday.
Thank you for the information. Doug, I took into consideration your concern for naming my table and have changed it. I was using names just as a test, did not think about the concerns. I have tried this on 2 computers, one at home and one at work. While at home, taking out that one line seemed to make it work, I did not change anything else. I do not completely understand this code, so I don't know why, or if, it made a difference. I looked up the error code online and it said one of the possible reasons is that I had an object set to nothing. I took it out and it seemed to work. However, when I got back to work this morning, using the code that worked at home did not work at the office. I am still getting the Runtime error 91 Object variable or With block variable not set. No difference if I put that line back in. Here is my current code.
Option Compare Database
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Function TP()
Dim dbcurr As DAO.Database
Dim rsLOGPRNT As DAO.Recordset ' rs is recordset and table name
Dim myLOGPRNTpath As Variant 'path name for document to print
Dim myprint As Variant 'dim created to capture when print check box is checked
Dim mycurrentbase As Variant
Dim mypreviousbase As Variant
Dim mysql As String 'sets print_flag to checked after command to print is sent
Dim strSQL As String

Set dbcurr = CurrentDb()
strSQL = "Select * From Releases " & _
"ORDER BY Releases.Field2;"
Set rsLOGPRNT = dbcurr.OpenRecordset(strSQL)
mypreviousbase = rsLOGPRNT![Field2]
Do While Not rsLOGPRNT.EOF
myLOGPRNTpath = rsLOGPRNT![Path] & rsLOGPRNT![Field2]
myprint = rsLOGPRNT![Print_flag]
mycurrentbase = rsLOGPRNT![Field2]
If myprint = False Then
CreateObject("Shell.Application").Namespace(0).ParseName(myLOGPRNTpath).InvokeVerb ("Print")
mysql = "UPDATE [Releases] SET [Releases].print_flag = -1 " & _
"WHERE Path = """ & rsLOGPRNT![Path] & """ " & _
"AND Field2 = """ & rsLOGPRNT![Field2] & """;"
' Debug.Print mysql
dbcurr.Execute mysql, dbFailOnError
End If
rsLOGPRNT.MoveNext
Sleep (3000) 'Sleep for 3 seconds
Loop

rsLOGPRNT.Close


End Function

Albert, while printing in order would be great, and was what I wanted, it is not a necessity. We often times print thousands of documents and then have to alphabetize. This is not always in our hands. Sometimes the documents sent to us are all in one large pdf, but are not alphabetized within itself, therefore we have to do this after print. So if I can get the individual documents to just print all out, we can still alphabetize like we do with the others. But thank you for the information. I may try to look at that down the line.
Can anyone help me with the run time error please? I get the error on the CreateObject("Shell.Application").Namespace(0).ParseName(myLOGPRNTpath).InvokeVerb ("Print") line. The only difference between the two machines is that at home I have access 2003, at work I have 2000.
Go to the top of the page
 
AlbertKallal
post May 31 2011, 10:46 AM
Post#36


UtterAccess VIP
Posts: 2,617
Joined: 12-April 07
From: Edmonton, Alberta Canada


Have you tested the line of code as such as the following behind a button on a form?
On other words for testing I suggest you put your code aside for now.
On a test form simply behind one button try the following code:
Dim strF As String
strF = "c:\t.pdf"
CreateObject("Shell.Application").Namespace(0).ParseName(strF).InvokeVerb ("Print")
Of course Replace "c:\t.pdf" with an legitimate path name to a known and legitimate PDF document you have. (and one without ANY spaces in the path name or doc name).
Now try running the above code, as mention there's no use trying to post all kinds of code and running around like a chicken with your head cut off if the above code will not work.
Osuspect this might be an issue if the file name has actual spaces in it or not, and I would strongly suggest that you test the above code in both scenarios. In other words attempt to print an PDF document that doesn't have any spaces in the full qualified path name to that document. Then IF THAT works then test again with a document that does have spaces in it. This will yield perhaps one of the solutions to one problem here that we will need to fix later one. And if neither the above works, then the issue is the right click print menu setup is different on that target computer . Remember as I stated, the above code ONLY works in scenarios in which on the particular target computer you can right click on on a file to print it.
So in fact, the first thing you want to do here before writing writing any code is to find a PDF document on your computer, right click on it and choose the print option and see that sends it out to the printer. If the steps done manually do not work, or you get some kind of additional prompts for that priinting, then none of the code we are attempting to run will also then work. This could even be something so simple as the incorrect default printer, or your default printer being a PDF printer, of course which then would throw up some kinda prompt for the user to enter something, but that cannot occur when you're using your code and thsu it will fail.
We need to resolve the above issues.
So first verify that you can print with the manual test of printing via right click with the mouse (so we not even using code here).
Next then is the above little test of above two lines of code to print a pdf document without spaces in the file name.
Then the third test of printing a file name with spaces in it. At each step along the way, if something doesn't work, it is 100% waste of time to move forward to the next step in testing.
So, lets verify that the above 3 things work.
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
kallal@msn.com
Go to the top of the page
 
Doug Steele
post May 31 2011, 10:55 AM
Post#37


UtterAccess VIP
Posts: 21,732
Joined: 8-January 07
From: St. Catharines, ON (Canada)


I think this might be the issue!
Albert: if the path does have spaces in it, would the code be
CreateObject("Shell.Application").Namespace(0).ParseName(Chr(34) & strF & Chr(34)).InvokeVerb ("Print")
?
Go to the top of the page
 
caosity
post May 31 2011, 11:21 AM
Post#38



Posts: 16
Joined: 26-May 11



Albert,
I have run all three tests, all three work. I tried files with spaces in the file name, not the path, and files with no spaces, both printed. This code did work on my computer at home. Just not here. Both are running XP with SP3, the only difference is Access 2000 vs. Access 2003. This may be way off base, but could this be related to a reference library?
Go to the top of the page
 
AlbertKallal
post May 31 2011, 11:23 AM
Post#39


UtterAccess VIP
Posts: 2,617
Joined: 12-April 07
From: Edmonton, Alberta Canada


Hi Doug,
Actually, I was just covering my bases. Turns out that surround with quotes is NOT needed, and in fact it fails if I add them (and I did NOT know this).
just had not tested this issue and was being careful. However, what is interesting is that any time a incorrect file name is supplied, then of course the createobject fails with the
"object variable or with block variable not set".
In other words based on testing from your suggestion, we now know any incorrect file name supplied is the source of the particular error message in question .
On that note I am going out for coffee. So while your suggest is not a fix and in fact does not work, it did shed light on this issue. I have used this in the past with spaces.
Anyway, me telling you that it helped us shed light on this issue should at least make you feel better for helping us anyway hat_tip.gif
We much down to bad path or file name, or simply that no right click option is available. There also one more possbile, and I seen on xp boxes, you need to use:
InvokeVerb ("&Print")
but on win 7 boxes, you use
InvokeVerb ("Print")
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
kallal@msn.com
Go to the top of the page
 
caosity
post May 31 2011, 11:44 AM
Post#40



Posts: 16
Joined: 26-May 11



My apologies to all. As is often the case, the problem this time just happen to be between the headsets. My path field was missing a "\" character. Searching the internet for the runtime error did not once indicate that it could have been a bad filename or path. I have corrected the path in the table to include the character and it is now printing.
Thanks to everyone that helped me, especially Doug, Albert, and JLeach. Here is my final code:
Option Compare Database
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Function TP()
Dim dbcurr As DAO.Database
Dim rsLOGPRNT As DAO.Recordset ' rs is recordset and table name
Dim myLOGPRNTpath As Variant 'path name for document to print
Dim myprint As Variant 'dim created to capture when print check box is checked
Dim mycurrentbase As Variant
Dim mypreviousbase As Variant
Dim mysql As String 'sets print_flag to checked after command to print is sent
Dim strSQL As String

Set dbcurr = CurrentDb()
strSQL = "Select * From Releases " & _
"ORDER BY Releases.Field2;"
Set rsLOGPRNT = dbcurr.OpenRecordset(strSQL)
mypreviousbase = rsLOGPRNT![Field2]
Do While Not rsLOGPRNT.EOF
myLOGPRNTpath = rsLOGPRNT![Path] & rsLOGPRNT![Field2]
myprint = rsLOGPRNT![print_flag]
mycurrentbase = rsLOGPRNT![Field2]
If myprint = False Then
CreateObject("Shell.Application").Namespace(0).ParseName(myLOGPRNTpath).InvokeVerb ("Print")
mysql = "UPDATE [Releases] SET [Releases].print_flag = -1 " & _
"WHERE Path = """ & rsLOGPRNT![Path] & """ " & _
"AND Field2 = """ & rsLOGPRNT![Field2] & """;"
' Debug.Print mysql
dbcurr.Execute mysql, dbFailOnError
End If
rsLOGPRNT.MoveNext
Sleep (2000) 'Sleep for 2 seconds
Loop

rsLOGPRNT.Close


End Function
Go to the top of the page
 
3 Pages V < 1 2 3 >


Custom Search
RSSSearch   Top   Lo-Fi    22nd May 2018 - 05:19 AM