Only merge a new record, not all

  • Thread starter Caroline Higson
  • Start date
C

Caroline Higson

Hello

I have a command button to open Word 03 from Access 03, merge the
fields and then print them out. I only want the merge to print out the
latest record addition to the database, but it prints out every single
record in it. Is there any code I can input into my existing vb to do
this automatically?

Thank you very much,

Code as follows:

Private Sub Command42_Click()

Dim objWord As Object
Set objWord = GetObject("C:\Documents and Settings\Owner\My
Documents\welcome letter.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the Rat Rescue database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\Owner\My
Documents\document.mdb", _
LinkToSource:=True, _
Connection:="TABLE Sponsors", _
SQLStatement:="SELECT * FROM [Sponsors]"

objWord.MailMerge.Destination = wdSendToNewDocument
objWord.MailMerge.Execute

objWord.Application.Options.PrintBackground = False
objWord.Application.ActiveDocument.PrintOut

End Sub
 
B

Brendan Reynolds

You need to add to your SQL statement a WHERE clause that will select the
record you want. For example, if your table includes an incrementing
AutoNumber field, you could use something like ...

SELECT * FROM Sponsors WHERE SponsorID = (SELECT Max(SponsorID) FROM
Sponsors)

.... where 'SponsorID' is the name of the incrementing AutoNumber field.

If you have a field that records the date and time that a record was added,
you can use that instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top