Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a group of letters at once.

Status
Not open for further replies.

needadvice

Programmer
Apr 7, 2002
145
US
Can someone start me in the right direction on:
How to enter records into a table, then print a group of various letters based on a field value(letter type).
 
Hi,
Let us assume you create a table called letters. Let this have the following fields:
name Text
address Text
Zip Text
Type Text

Design a form that has 4 text boxes with labels Name, Address,Zip and Type respectively.

Add a command button called addRecord and change its caption to Add.

Set a refernce to the DAO library using the refernces option on the tool bar.

In the On Click event of the command button, type in the following code:

Private Sub addRecord_Click()
Dim db as database
Dim rs as recordset
set db=currentdb
set rs=db.openrecordset("letters",dbopendynaset)
rs.addnew
rs.fields("name")=Me.Text1 'Text box for name
rs.fields("address")=Me.Text2 'Text box for address
rs.fields("Zip")=Me.Text3 'Text box for Zip
rs.fields("type")=Me.Text4 'Text box for Type
rs.update
rs.close
db.close
set rs=nothing
set db=nothing
End Sub

This is the code for adding records to a table.

Now, for printing a set of letters based on the type, follow the steps below:

Query Creation:
--------------
i) Create a query called reportQuery in the Query Design window.

ii) In that query select the fields as individual fields instead of using the letters.* option.

iii) Save the query using the name above.

Modifications to form to allow printing :
----------------------------------------
iv) Add a command button to the existing form and name it as cmdPrintReport and set its caption to Print Report.

v) Add a text box called Text5 to the form.


Creation of the report :
-----------------------
vi) Open a new report in the design view.

vii) Set the Record Source property of the report to reportQuery. ( the query we created now ).

viii) Add three text boxes to the detail section of the report.

ix) Set the Control Source property ( available under the Data Tab of the properties box ) of the first text box to name.

x) Set the Control Source property ( available under the Data Tab of the properties box ) of the second text box to address.

xi) Set the Control Source property ( available under the Data Tab of the properties box ) of the third text box to zip.

xii) Save the report under the name rptLetters.


Now that we have finished the designing processes, put the following code in the click event of the cmdPrintReport button that we have just added to the form:

Private Sub cmdPrintReport_Click()

dim qd as querydef
set qd=currentdb.querydefs("reportQuery")
qd.SQL="Select * from letters where type='" & Me.Text5 & "'"
qd.close
Docmd.openreport "rptLetters",acViewPreview

End Sub

Using the acViewPreview option int eh above stmt. ensures that you get to see the preview of the report. If you omit this it will print to the default printer.

Hope this helps you. Please let us know what happens.
 
Hi,
Let us assume you create a table called letters. Let this have the following fields:
name Text
address Text
Zip Text
Type Text

Design a form that has 4 text boxes with labels Name, Address,Zip and Type respectively.

Add a command button called addRecord and change its caption to Add.

Set a refernce to the DAO library using the refernces option on the tool bar.

In the On Click event of the command button, type in the following code:

Private Sub addRecord_Click()
Dim db as database
Dim rs as recordset
set db=currentdb
set rs=db.openrecordset("letters",dbopendynaset)
rs.addnew
rs.fields("name")=Me.Text1 'Text box for name
rs.fields("address")=Me.Text2 'Text box for address
rs.fields("Zip")=Me.Text3 'Text box for Zip
rs.fields("type")=Me.Text4 'Text box for Type
rs.update
rs.close
db.close
set rs=nothing
set db=nothing
End Sub

This is the code for adding records to a table.

Now, for printing a set of letters based on the type, follow the steps below:

Query Creation:
--------------
i) Create a query called reportQuery in the Query Design window.

ii) In that query select the fields as individual fields instead of using the letters.* option.

iii) Save the query using the name above.

Modifications to form to allow printing :
----------------------------------------
iv) Add a command button to the existing form and name it as cmdPrintReport and set its caption to Print Report.

v) Add a text box called Text5 to the form.


Creation of the report :
-----------------------
vi) Open a new report in the design view.

vii) Set the Record Source property of the report to reportQuery. ( the query we created now ).

viii) Add three text boxes to the detail section of the report.

ix) Set the Control Source property ( available under the Data Tab of the properties box ) of the first text box to name.

x) Set the Control Source property ( available under the Data Tab of the properties box ) of the second text box to address.

xi) Set the Control Source property ( available under the Data Tab of the properties box ) of the third text box to zip.

xii) Save the report under the name rptLetters.


Now that we have finished the designing processes, put the following code in the click event of the cmdPrintReport button that we have just added to the form:

Private Sub cmdPrintReport_Click()

dim qd as querydef
set qd=currentdb.querydefs("reportQuery")
qd.SQL="Select * from letters where type='" & Me.Text5 & "'"
qd.close
Docmd.openreport "rptLetters",acViewPreview

End Sub

Using the acViewPreview option int eh above stmt. ensures that you get to see the preview of the report. If you omit this it will print to the default printer.

Hope this helps you. Please let us know what happens.
 
Thanks,
I'll give this a try and let you know the results.
 
After examining your code it appears to me that it will only print one letter at a time. I already have a table and insert records. I need to print all the letters at one click of a print command button. The problem is that the letters are each different and I need a way to print down the recordset identifying each letter by a field (letter type). How do I identify the type of letter and print accordingly.
I've tried Dlookup but this only retuns one value. I need some other way.
Any further ideas?
 
Hi,
I assume you have a field in the table that identifies each letter as belonging to a particular type. By specifying the type, you can print all letters of that type.

If I have got you wrong, please send the table structure. We will work furhter using that.
 
Try creating a seperate query filter that extracts just the records with the field type you want to print. (say ZIp code or other letter type identifier). Then create a form based on that filtered query. The form shold be formatted like your letter:
-Logo, return address, etc in page/form header).
-Text of letter as text box.
-Field names that will change with each letter (adressee, address, etc) as controls.

Then view the form in continuous view. You should have multiple "letters" for only the filtered records. Do print preview and then print. You may need to insert a page break (or I think you can set a property) to print each letter on a seperate page. To do a different group of letters, simply change the filter.

Hope this works. Let me know the outcome.

JDTTEK
 
This is the same question I have, but what how do you activate a continuous view here??
 
I THINK I'M HAVING A PROBLEM EXPLAINING THIS. I WANT TO ADD RECORDS TO A TABLE. THEN, CLICK A BUTTON AND HAVE THEM ALL PRINT. EACH IS A DIFFERENT LETTER. YES, THERE IS A FIELD IN THE TABLE POPULATED BY THE DATA ENTRY FORM, WHICH IDENTIFIES THE LETTER TYPE. THE PROBLEM IS WHEN YOU PRINT FROM A TABLE IT IDENTIFIES THE FIRST TYPE OF LETTER THEN MAKES ALL THE LETTERS THAT TYPE. THE ADDRESSES ARE DIFFERENT BUT THE BODY OF THE LETTER DOESN'T CHANGE WITH EACH LETTER.
HOPE THIS MAKES SENSE TO SOMEONE.
I NEED TO HAVE IT GO BACK EACH TIME AND LOOK FOR THE LETTER TYPE WITHOUT THE USER DOING ANYTHING BUT CLICKING THE PRINT BUTTON ONCE.
 
Are you trying to do the following:
1.Data entry form identifies the letter type (ie- A=Merry xmas, B=Happy b'day, C=Happy Thanksgiving, etc).
2. Same form has address fields for reciepient.
3. When you press print button, you want the appropriate letter to print out depending on the letter type for that record?
4. You want to print the whole batch, with each letter different, rather that one letter at a time.

If this discribes what you are trying to do, then I think I have a way. Let me know by reply. If not, then I still do not understand the problem.

jdttek
 
What you need to do is WORD MAILMERGE through a RunAPP in ACCESS. Be sure and set the reference to WORD before creatiing a WORD object.

Rollie E
 
Mailmerge is a new area to me. It sounds like it'll work. May take me some time, but I'll give it a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top