473,324 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Printing a single record to a word document

3
I have my word document setup with bookmarks and it will print out all of my records each on a separate page. What I am wanting to do is select which record to print and dumping the rest of the records and not save the extra documents.
Expand|Select|Wrap|Line Numbers
  1. Public Sub btnPrintInv_Click()
  2. Dim wApp As Word.Application
  3. Dim wDoc As Word.Document
  4. Dim rsInvoice As Recordset
  5.     Set wApp = New Word.Application
  6.     Set wDoc = wApp.Documents.Open("C:\DECA Database\DECAInv.docx")
  7.     Set rsInvoice = CurrentDb.OpenRecordset("qryHGInv")
  8.  
  9.     If Not rsInvoice.EOF Then rsInvoice.MoveFirst
  10.  
  11.         Do Until rsInvoice.EOF
  12.             wDoc.Bookmarks("MTicket").Range.Text = Nz(rsInvoice!Mticket, "")
  13.             wDoc.Bookmarks("TCustomerNumber").Range.Text = Nz(rsInvoice!TCustomerNumber, "")
  14.             wDoc.Bookmarks("TCustomerName").Range.Text = Nz(rsInvoice!TCustomerName, "")
  15.             wDoc.Bookmarks("CName").Range.Text = Nz(rsInvoice!CName, "")
  16.             wDoc.Bookmarks("Street").Range.Text = Nz(rsInvoice!Street, "")
  17.             wDoc.Bookmarks("City").Range.Text = Nz(rsInvoice!City, "")
  18.             wDoc.Bookmarks("State").Range.Text = Nz(rsInvoice!State, "")
  19.             wDoc.Bookmarks("Zip").Range.Text = Nz(rsInvoice!Zip, "")
  20.             wDoc.Bookmarks("Phone").Range.Text = Nz(rsInvoice!Phone, "")
  21.             wDoc.Bookmarks("Suite").Range.Text = Nz(rsInvoice!Suite, "")
  22.             wDoc.Saveas2 "C:\DECA Database\" & rsInvoice!Mticket & "Inv" & Format(Now(), "mmddyy") & ".docx"
  23.                 rsInvoice.MoveNext
  24.  
  25.         Loop
  26.             wDoc.PrintOut
  27.  
  28.             wApp.Quit
  29.             Set wApp = Nothing
  30.             Set wDoc = Nothing
  31. End Sub
Apr 4 '19 #1
6 1099
twinnyfo
3,653 Expert Mod 2GB
ten102,

Welcome to Bytes!

What I am wanting to do is select which record to print and dumping the rest of the records and not save the extra documents.
I'm not exactly sure what your request is here. If you are looking for exclusive records, then simply set the appropriate criteria in your Query qryHGInv (or use a different query).

I'm not sure what you mean by "dumping the rest of the records" unless you simply mean not using any of them.

Hope this hepps!
Apr 4 '19 #2
NeoPa
32,556 Expert Mod 16PB
Too much wrong with the code to cover all now but using CurrentDb() directly is likely to cause you problems.
In line with what Twinny's already suggested you might like to change things to something like :
Expand|Select|Wrap|Line Numbers
  1. 'Insert after line #1
  2. Dim strSQL As String
  3. 'Instead of your line #7
  4.     strSQL = Replace("SELECT * FROM [qryHGInv] WHERE ([YourField]=%V)" _
  5.                    , "%V", XXX)
  6.     Set rsInvoice = CurrentDb().OpenRecordset(strSQL)
Whatever field you use to determine the page you're after is what you'll use for [YourField] and XXX is whatever reference you have to the value of that.
%V is fine as it stands if the value is numeric but dates and string literal values are treated differently so you may need to adjust to handle (See Literal DateTimes and Their Delimiters (#)).

Good luck.
Apr 4 '19 #3
ten102
3
I have 15 customer records. The code I am using produces 15 documents. I only want to select and print 1 customer record not all 15.
Apr 4 '19 #4
NeoPa
32,556 Expert Mod 16PB
Just to be clear, that was in response to Twinny's question in his post. Well done for answering such questions.

Now you need to consider where you're at in response to everything that's been posted.
Apr 4 '19 #5
ten102
3
I am not as sharp as most of you on this subject. I will just stick with the ugly InputBox to extricate the record I want to print on my word document.
Apr 5 '19 #6
twinnyfo
3,653 Expert Mod 2GB
Just to be clear, the “ugly InputBox” might not necessarily be an “ugly” solution. However, the key that solves this problem is reducing the record set from “all records” to “one record”. Many ways to do that, but that is, in fact, the answer.
Apr 6 '19 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jeff Harbin | last post by:
I've got an ACCESS 2000 application that I'm developing. One of the outputs of this app will be to generate a series of 'jobs' which corresponds to a record in the database. Each record will be...
4
by: Otis Hunter | last post by:
I have been given an Access Database which contains a table that has an OLE object field that contains a Word document. That table contains hundreds of records. I would like to find out how I can...
0
by: Otis Hunter | last post by:
I have been fighting with this for days and your expert help is needed! Below is the code I am executing which results with "Object doesn't support this property or method". The error is occuring...
9
by: ewolfman | last post by:
Hi, I need to provide the user with the option to click something, and what follows is: 1. Download a word document, without displaying winword. 2. Printing the document to the default printer...
4
by: no8do | last post by:
Hi there, I am brand new in access and VBA programming and I am asking for your help. One of the fields in my db is of the OLE object data-type. I' ve written a vb script that is executed on a...
2
by: madval | last post by:
hi, i need your help, i'll receive some ms word documents (paragraphs, bullets, different fonts in a document -family-size-format, images, etc. a "normal" document) and i need to print them on a...
17
by: wparrott | last post by:
Hello experts! I'm having trouble coding a button on a form and could use some help. In a nutshell, I'm attempting to code the button to do the following: 1. Choose the appropriate Word...
0
by: corcoranj | last post by:
Hello everyone, I have a series of Microsoft word documents, gathered via a SQL query. I would like to be able to print these documents, no matter the number to the clients computer. I have tried...
0
by: accessdumbie | last post by:
We have a small amount of information in a Word Document that I would like to print in an Access Report. We have the location of the document for each individual record stored in a hyperlink field...
1
by: powermetal114 | last post by:
Hi, following Peoblem: I have a PDF-file. I woud like to insert a field, code or whatever between two Pages in MS-Word as a printer-instruction. The idea is to print the whole Word Ducument then...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.