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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get current date (now()) in mailmerge 1

Status
Not open for further replies.

AT76

Technical User
Apr 14, 2005
460
0
0
US
Hi,

I have created a mail merge that opens up Word from my access application. I would like to write today's date (Now()) in that current word doc.

I've tried using the following but they don't work:

.Add oSel.Range,
oSel.TypeText

Any suggestions?

Thank you!

 
Hi,

I wanted to check again if anyone knows how to accomplish this? Thanks for your help.
 
did you try using Date() instead? Now() returns date and time. If you create the field in your query that feeds the merge you can insert it in the word document.
 
dtay1132,

Do I just type Date() in vba?

Is there any extra code that goes along with it for word?

Thanks!
 
When I type "Date()" I get syntax error...
 
Here's my code:

Private Sub cmdMailMerge_Click()
'Dim objWordApp As Word.Application
'Dim objWord As Word.Document
'Dim oSel As Word.Selection

Set objWordApp = CreateObject("Word.Application")
Set objWord = objWordApp.Documents.Add

' Make Word visible.
objWord.Application.Visible = True
objWord.MailMerge.OpenDataSource _
Name:="C:\Documents and Settings\....
LinkToSource:=True, _
Connection:="TABLE tblVendorInfo", _
SQLStatement:="Select * from [tblVendorInfo]"

'Add fields
With objWord.MailMerge.Fields
Set oSel = objWord.Application.Selection

Date ()
oSel.TypeParagraph
oSel.TypeParagraph
oSel.TypeParagraph
oSel.TypeText "To: "
'.Add oSel.Range, "First"
oSel.TypeText " "
'.Add oSel.Range, "Last"


End With
' Execute the mail merge.
objWord.MailMerge.Execute
objWord.Close (0)

Set objWord = Nothing
End Sub
 
Actually what I was thinking would work is rather than merging directly from a table, use a MSAccess query to pull the records for the merge instead of SQL. In the query create a field called something like

CurrentDate: Date()

And use that field to populate the field in your merge word document.

I'm not too great at SQL or VB, but this approach has worked for me in the past to provide a current date for forms and reports within Access. No reason it wouldn't work for a mergemail.
 
I prefer this method. Thanks for the advice though.

Does anyone know the correct syntax to display the date as ie. September 11, 2005 in word using vba?

Thank you!
 
A starting point:
oSel.InsertDateTime DateTimeFormat:="dddd d MMMM yyyy", InsertAsField:=False

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV you are AWESOME!!! Thank you!

AT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top