473,399 Members | 3,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Requested object is not available

I am using Microsoft Access 2010 and the following VBA script below to complete a Word Mail Merge. When I run it I get an error message saying "Requested object is not available". It opens the merge document but doesn't complete the merge. It worked fine when using Access/Word 2003 but crapped out when we switched to Access/Word 2010. Any help would be greatly appreciated.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Open_Word_App_Click()
  2. On Error GoTo Err_Open_Word_App_Click
  3.  
  4.     Dim oApp As Object
  5.  
  6.     Set oApp = CreateObject("Word.Application")
  7.     oApp.Visible = True
  8.     FacID = Me![Penske_ID]
  9.     oApp.Documents.Open "\\ghna01aptl\\administration$\\Environmental\\SPCC_template\Penske SPCC Merge.docx"
  10.  
  11.     oApp.ActiveDocument.MailMerge.DataSource.QueryString = _
  12.         "SELECT * FROM `GES_SPCC` WHERE (([Penske_ID] = '" & Me![Penske_ID] & "'))" & ""
  13.  
  14.         oApp.ActiveDocument.MailMerge.Destination = 0
  15.         oApp.ActiveDocument.MailMerge.MailAsAttachment = False
  16.         oApp.ActiveDocument.MailMerge.MailAddressFieldName = ""
  17.         oApp.ActiveDocument.MailMerge.MailSubject = ""
  18.         oApp.ActiveDocument.MailMerge.SuppressBlankLines = True
  19.         oApp.ActiveDocument.MailMerge.DataSource.FirstRecord = 1
  20.         oApp.ActiveDocument.MailMerge.DataSource.LastRecord = 1
  21.  
  22.         oApp.ActiveDocument.MailMerge.Execute Pause:=True
  23.  
  24.         oApp.Documents("Penske SPCC Merge.docx").Close SaveChanges:=0
  25.  
  26.         FacID = ""
  27.  
  28. Exit_Open_Word_App_Click:
  29.     Exit Sub
  30.  
  31. Err_Open_Word_App_Click:
  32.     MsgBox Err.Description
  33.     Resume Exit_Open_Word_App_Click
  34.  
  35. End Sub
Apr 16 '14 #1
4 3922
NeoPa
32,556 Expert Mod 16PB
Let's start by sharing the line # the code crashes on. Without this there isn't really a question.
Apr 17 '14 #2
zmbd
5,501 Expert Mod 4TB
To help get the line# that Neopa is asking for,

COMMENT out line 2, don't delete it as you can put it back after the troubleshooting.
(^_^)

ADD the STOP command at line 3

Now when your code encounters the STOP command you should go into debug mode where you can use [F8] to step thru the code until you find the error.

Please note the line the error occurs on and Please post the EXACT title, number, and text of the error message. Please do not alter, omit, nor abreviate the information provided in the error message
Apr 17 '14 #3
OK, when I get to the line of code below I get a Run time error "5852" Requested object is not available.

Expand|Select|Wrap|Line Numbers
  1. oApp.ActiveDocument.MailMerge.DataSource.QueryString = _
  2.         "SELECT * FROM `GES_SPCC` WHERE (([Penske_ID] = '" & Me![Penske_ID] & "'))" & ""
Apr 17 '14 #4
NeoPa
32,556 Expert Mod 16PB
That looks like line #11 then.

The obvious issue here (Obvious to us that is) is that the quote characters used are not correct quote characters, but something used when working in a document editor (Like MS Word for instance, as opposed to a text editor). If you replace these characters with single quotes then you should get past this problem.

As a very strong recommendation - never work on code in a word processor or document editor. It includes characters that make sense when displaying information but are very unhelpful when trying to produce code.
Apr 17 '14 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Trond | last post by:
I have a dictionary which is ca 40mb in size. I need this dict to be available for each apache/mod_python thread. But since it is so big, I cannot allow each thread to retain a copy of the dict,...
2
by: Christopher W. Douglas | last post by:
I am working on a project in VB.NET using Visual Studio.NET 2003. I use dialog windows to get user information, and throw exceptions when there are user errors, such as leaving a field blank or...
5
by: LL | last post by:
Hi, Where is the best place to check the session's object, if it's null, then redirect the user to login page? put into every page's load event? Thanks.
1
by: Jim P. | last post by:
I'm having trouble returning an object from an AsyncCallback called inside a threaded infinite loop. I'm working on a Peer2Peer app that uses an AsyncCallback to rerieve the data from the remote...
1
by: John Davy | last post by:
I am trying to set up a mail merge by automation using a text file as the data source but I keep getting the message "Requested object is not available" and the debugger stops on the...
1
by: Mike Kline | last post by:
Hi There! How do I make the Objects in the custom made HttpModule available to ASPX page or ASCX controls without requiring an object reference? For example, SessionState HttpModule made the...
5
by: aaapaul | last post by:
Hello ! I have some values stored in a xml-file. When starting my application, I read this file and store the values in a collection object. My problem is the error-handling, if the fieldname...
0
by: mbbostwick | last post by:
I have a problem with a mail merge procedure I used to use with Access '97. We recently converted to Office XP (2002) and I now have an issue I am unfamilliar with and have been unable to...
5
by: Andy B | last post by:
I am trying to figure out how to make an object instance available for all methods of a class. I tried to do something like this: public class test { TheObject Instance = new TheObject();...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...
0
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,...

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.