Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

Thread Tools Rate Thread Display Modes
Old 11-02-2006, 01:34 AM   #1
Registered User
Join Date: Jun 2005
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
danian is an unknown quantity at this point
Word Mail Merge Bookmark Problem IF Problem

I found a piece of code here that works great, but have found a little bug. The code is:

Dim dbs As DAO.Database
Dim rstMergeThese As Recordset
Dim oApp As Object

Set oApp = CreateObject("Word.Application")
oApp.Visible = True

With oApp
.Documents.Open "C:\Temp\Service_Plan_Schedule.dot"
' Move to each bookmark and insert text from the form.

'Contract Details
.selection.Text = (CStr(Forms!frmClientDetails!Name))

.selection.Text = (CStr(Forms!frmClientDetails!Address))

.selection.Text = (CStr(Forms!frmClientDetails!Tel_Home))

.selection.Text = (CStr(Forms!frmClientDetails!Work_Home))

'if word isn't running, start and activate it
If Err Then
Shell "C:\Program Files\Microsoft Office\Office\" & "WinWord / Automation", vbMaximizedFocus
AppActivate "Microsoft Word"
End If
' Print the document in the foreground so Microsoft Word 97
' will not close until the document finishes printing.
''.ActiveDocument.PrintOut Background:=False
' Close the document without saving changes.
''.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
' Quit Microsoft Word and release the object variable.
Set oApp = Nothing

End With

When a form is open, you click the cmd button and it copies the fields above to bookmarks I have in word, but the bug I have found is that if the textbox in access does not have any data in it the code stops. Therefore I need some kind of if statement which basically says:

IF Forms!frmClientDetails!Name is BLANK then leave sps_Name Blank
.selection.Text = (CStr(Forms!frmClientDetails!Name))

But I am not sure how to write the code.

danian is offline   Reply With Quote
Old 11-02-2006, 03:46 AM   #2
Registered User
alastair69's Avatar
Join Date: Dec 2004
Location: Leeds, West Yorkshire, UK
Posts: 562
Thanks: 0
Thanked 9 Times in 7 Posts
alastair69 is on a distinguished road
Do you have a copy of Service_Plan_Schedule.dot file so i can have a look for you.
If I have helped, please add to my reputation!
alastair69 is offline   Reply With Quote
Old 11-06-2006, 02:50 AM   #3
Registered User
Join Date: Jul 2005
Location: Newcastle, Australia
Posts: 50
Thanks: 0
Thanked 1 Time in 1 Post
jubb is on a distinguished road
Send a message via MSN to jubb
Thumbs up

Try this out, it should do what you want

if isnull(Forms!frmClientDetails!Name) then 
'i usually display a message here asking the user to enter the missing data
'then set my controls and objects to nothing and exit the sub
' i also add code here to check if the bookmark exists in the document 
if .activedocument.bookmark.exists("sps_Name") then
.selection.Text = (CStr(Forms!frmClientDetails!Name))
end if
end if
Let me know if you have any probs.



jubb is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Mail Merge Blue6688 Forms 1 07-10-2005 05:05 AM
Individual records exported to word mail merge? ddiver General 3 05-12-2005 05:57 AM
Mail Merge from a Query expublish Forms 1 03-07-2002 08:36 AM
Mail Merge with Word 97 alguzman Forms 0 10-15-2001 06:53 AM
Mail merge with Word Tim Johnson Reports 2 03-14-2000 04:38 AM

All times are GMT -8. The time now is 10:32 PM.

Microsoft Access Help
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post

Sponsored Links

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World