473,516 Members | 3,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VBA - MailMerge error 2046

Hi All,

I have a table in the database and a Word document saved on the hard disk. I
want to mailmerge the content of the table into the word document, all done
in vba.

Any examples?

I tried this:

DoCmd.SelectOnject acTable, "myTable", true
DoCmd.RunCommand acCmdWordMailMerge

and I get run-time error 2046, "The command or action 'WordMailMerge' isn't
available now.

Regards,
Nicolae

Nov 13 '05 #1
2 3293
Hi again,

I solved this problem. It should be like this:

Private Sub Command0_click()
Set db = CurrentDb
Set qdf = db.QueryDefs("qryTemp")
Dim strDocName as String

Set oApp = CreateObject("Word.Application")
Set tdf = Nothing
On Error resume next
Set tdf = CurrentDb.TableDefs("tblMailMerge")
db.TableDefs.Delete "tblMailMerge"
db.TableDefs.Refresh
On error go to 0

qdf.SQL = "Select Firstname, Surname into tblMailMerge from tblCustomers"
qdf.Execute dbFailOnError
strDocName = "C:\Docs\mydoc.doc"

oApp.Visible = true
oApp.Application.Documents.Open strDocName

Set oApp = Nothing
End Sub

There might be some bugs (regarding deleting the table tblMailMerge when it
doesn't exist), since I am still developing it, but I solved the initial
error

Regards,
Nicolae
Nov 13 '05 #2
> There might be some bugs (regarding deleting the table tblMailMerge when it
doesn't exist), since I am still developing it, but I solved the initial
error


So write a function to see if the table exists If not, exit the code.
Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1909
by: Shannon Rotz | last post by:
I have a function in a Microsoft Access module (below) which creates a Word XP Mailmerge document, drawing the data from Access XP. I can get the connection to work fine. However, when I create the form letters, the data from certain merge fields is missing. When I view the data in the MailMerge Recipients dialog box, the data is not there...
4
12036
by: Ray Todd Jr | last post by:
I can't get ths code to correctly execute. After I have clicked on a Access Form, I want the code to open the word document, merge the data, print the forms and then close the two windows that open of Word. The Mail Merge takes place, and the sticking point is that I have to manually close the two Word Windows. Can someone please tell me...
5
2374
by: Dixie | last post by:
I have a mailmerge that works fine from an MDB database using the OpenDataSource method to send its data from a query within Access as part of an automation sequence. Now, if I compile that mdb into an MDE, when I click a button on the Access form that should produce the mailmerge, the template opens on the screen with the fields visible,...
0
1074
by: RH | last post by:
Hi, I'm trying to use mailmerge with Word2003 from an asp.net webpage I'm using the following code: Dim W As New Word.Application Dim D As Word.Document = W.Documents.Open("maindoc.doc") D.MailMerge.OpenDataSource("address.txt") D.MailMerge.Destination = Word.WdMailMergeDestination.wdSendToNewDocument D.MailMerge.Execute()
2
13484
by: Mikey | last post by:
Sample VB .NET source code to create mailing labels or customized letters using MS Word MailMerge This VB .NET source code will start MS Word and call methods and set properties in MS Word to execute a MailMerge to create mailing labels or customized letters. A label name known to MS Word MailMerge mailing label wizard may be used or a...
6
8737
by: tony.abbitt | last post by:
I have recently installed Office 2007 (SP1) retaining the previous installation of Office 2003. I have converted an Access 2003 database to Access 2007. The database contains the VBA code 'DoCmd.RunCommand acCmdLinkTables' to initiate the dialog box to rebuild links to tables held in a back-end Access database (which has also been...
5
3168
by: prakashwadhwani | last post by:
The Delete Event/Proc & "Save_Fields_In_Form_Header" Event/Proc in my form were working perfectly. However, after I added a call to the "Save_Fields_In_Form_Header" Event/Proc in the "Current" Event of my form, and I now try to Delete a record, I get ... Run-Time Error 3218 - Could not Update; Currently Locked. My Access application...
3
2051
by: MLH | last post by:
The following unexpected error occurred in AppSpecific Module's Sub Check4PastSaleDates(), line #350 when called from Cron Form: 2046: "The command or action 'SetWarnings' isn't available now." My error handler captured the problem condition and reported what you see above. Clicking OK in the msgbox led to other 2046 errors with other...
0
2531
by: dbsog7777 | last post by:
I was trying to use the sample code below, but I encountered two errors: Application.DoEvents() and AutoText(entry). I am not sure how to correct the errors. I trying to use the sample code to create a mailmerge routine that accepts data from my SQL database and create a word doc that ce be previewed in the client browser. My OS is XP Pro...
0
7182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7405
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7574
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7136
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7547
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5106
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3252
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
823
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.