Microsoft KB Archive/264764

= WD97: Run-time Error '5852' When You Search for Record in Data Source (Table) =

Article ID: 264764

Article Last Modified on 1/27/2007

-

APPLIES TO


 * Microsoft Word 97 Standard Edition

-



This article was previously published under Q264764





SYMPTOMS
When you run a macro to find a record in your Word data source, you may receive the following error message:

Run-time error '5852':

Requested object is not available.

For example, this problem occurs when you run the following macro in your Word mail merge data source (table): Sub MyFindRecord

ActiveDocument.MailMerge.DataSource.FindRecord FindText:=&quot;Text&quot;, _ Field:=&quot;Field_Name&quot;

End Sub where &quot;Text&quot; is the text that you are searching for, and &quot;Field_Name&quot; is the field of your data source that contains the text.

NOTE: The text that you are searching for and the field name that contains the text must be enclosed in quotation marks in your macro code.



WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

For more information about how to use the sample code in this article, click the article number below to view the article in the Microsoft Knowledge Base:

173707 OFF97: How to Run Sample Code from Knowledge Base Articles

To work around this problem, use the following macro to find text in a Word data source (table): Sub MyFindRecord

With Dialogs(wdDialogMailMergeFindRecord) .Find = &quot;Text&quot; .Field = &quot;Field_Name&quot; .Execute End With

End Sub



MORE INFORMATION
When you open your mail merge data source and use the Find Record button on the Database toolbar (on the View menu, point to Toolbars), you can use the Find in Field dialog box and find text in a specific field.

However, if you record this function and run the recorded macro, you receive the error message listed in the &quot;Symptoms&quot; section of this article. This error occurs either when you run the macro in a data source file (table) that is opened directly in Word, or when you click Edit Data Source on the Mail Merge toolbar and then click View Source in the Data Form.

Additional query words: vb vba vbe mailmerge

Keywords: kbdtacode kbmacro kbmacroexample kbprb kbprogramming KB264764

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.