Microsoft KB Archive/125434

= ADT2: How to Modify Reattach NWIND Module in SOLUTION.MDB =

Article ID: 125434

Article Last Modified on 6/13/2001

-

APPLIES TO


 * Microsoft Access Developer's Toolkit 2.0

-



This article was previously published under Q125434



Advanced: Requires expert coding, interoperability, and multiuser skills.



SUMMARY
The Reattach NWIND module in the Solutions sample application (SOLUTION.MDB) demonstrates a method of updating the connection information for attached tables in an application that uses multiple databases. This method assumes that a wizard utility database (WZLIB.MDA) is specified in the [Libraries] section of the MSACC20.INI file and that the MSAU200.DLL file is installed in the Microsoft Access directory. If these files are not loaded (such as when you are running a run-time version of Microsoft Access), then the method in the Solutions sample application does not work.

This article describes how you can modify the method in the Reattach NWIND module to work in a run-time environment.

NOTE: In Microsoft Access for Windows 95, the RefreshTableLinks module of the Solutions.mdb is completely self-contained. It does not rely on any references to a wizard library.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Access Basic, please refer to the "Building Applications" manual.



MORE INFORMATION
To modify the method in the Reattach NWIND module to work in a run-time environment, follow these steps while running the retail version of Microsoft Access. Each of these steps is described in detail later in this article.
 * 1) Import the sample code from SOLUTION.MDB.
 * 2) Add a user-defined type from the WZLIB.MDA file.
 * 3) Add declare functions from the WZLIB.MDA file.
 * 4) Modify the sample GetMDBName function.
 * 5) Modify the sample GetMDBName2 function.
 * 6) Modify the sample AreTablesAttached function.
 * 7) Add the MSAU200.DLL file to your application's Setup using the Setup Wizard.
 * 8) Call the AreTablesAttached function in your application's Autoexec macro.

The following sections describe in detail each of the steps above.

Step 1: Import the Sample Code from SOLUTION.MDB

 * 1) With your database open, choose Import from the File menu.
 * 2) In the Data Source box, select Microsoft Access and then choose OK.
 * 3) In the File Name box, select SOLUTION.MDB and then choose OK.
 * 4) In the Object Type box, select Modules. In the Objects In SOLUTION.MDB box, select Reattach NWIND and then choose the Import button.
 * 5) When you are prompted "Successfully imported 'Reattach NWIND'" choose OK.
 * 6) Choose the Close button.

Step 2: Add a User-Defined Type from the WZLIB.MDA File
Add the following Type statement to the Declarations section of the Reattach NWIND module you imported in the step above: Type GetFileNameInfo hwndOwner As Integer szFilter As String * 255 szCustomFilter As String * 255 nFilterIndex As Long szFile As String * 255 szFileTitle As String * 255 szInitialDir As String * 255 szTitle As String * 255 Flags As Long nFileOffset As Integer nFileExtension As Integer szDefExt As String * 255 End Type Note that this Type statement was copied from the wizard utility database (WZLIB.MDA) and renamed to avoid conflicts.

Step 3: Add Declare Functions from the WZLIB.MDA File
NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.   Add the following API declaration to the Declarations section of the Reattach NWIND module you imported: Declare Function MSAU_GetFileName Lib "MSAU200.DLL" Alias "#1" _ (gfni As GetFileNameInfo, ByVal fOpen As Integer) As Long Note that this function was copied from WZLIB.MDA and renamed to avoid conflicts.   Add the following API declaration to make the common dialog box modal.

NOTE: You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code. Declare Function MSA_FindWindow Lib "User" Alias "FindWindow" _ (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer 

Step 4: Modify the Sample GetMDBName Function
Follow these steps to modify the GetMDBName function to use the new type you defined above, make the Find Database dialog box modal, and use the database name you specify:   Search the GetMDBName function for the following line: Dim OFN As wlib_GetFileNameInfo   Modify the line as follows to reference the new type: Dim OFN As GetFileNameInfo   Search the GetMDBName function for the following line: OFN.hwndOwner = 0 </li>  Modify the line as follows to make the Find Database dialog box modal: OFN.hwndOwner = MSA_FindWindow("OMain", 0&) </li>  Search the GetMDBName function for the following line: OFN.szTitle = "Where is your NWIND.MDB?" </li> Change the line so that it uses the name of your database instead of NWIND.MDB.</li></ol>

Step 5: Modify the Sample GetMDBName2 Function
NOTE: In the following sample code, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

Follow these steps to modify the GetMDBName2 function to use the new type you defined above:   Find the following GetMDBName2 parameters line: Function GetMDBName2(gfni As wlib_GetFileNameInfo, ByVal fopen _     as Integer) As Long </li>  Modify the line to read: Function GetMDBName2(gfni As GetFileNameInfo, ByVal fopen _     as Integer) As Long </li>  Search the GetMDBName2 function for the following line: lRet = wlib_MSAU_GetFileName(gfni, fOpen) </li>  Modify the line as follows to reference the new type: lRet = MSAU_GetFileName(gfni, fOpen) </li></ol>

Step 6: Modify the Sample AreTablesAttached Function
Follow these steps to modify the AreTablesAttached function to look for a table in your attached database and replace references to NWIND.MDB and SOLUTION.MDB with references to your application:   Search the AreTablesAttached function for the following line: Set MyRecords = MyDB.OpenRecordset("Products") </li> Replace the Products table with the name of the appropriate table in your attached database.</li> Search for and replace all references to NWIND.MDB and SOLUTION.MDB. Replace these references with your database names.</li></ol>

Step 7: Add MSAU200.DLL to Application's Setup Using the Setup Wizard
When you create your application's Setup disks with the Setup Wizard, follow these steps to add the MSAU200.DLL file to the list of files to be included with your application:
 * 1) Start the Setup Wizard.
 * 2) Add your databases to the Files To Include list.
 * 3) Choose the Add File button.
 * 4) In the File Name box, type :\ \MSAU200.DLL where and are the hard disk and directory containing your copy of Microsoft Access. For example, if you have Microsoft Access installed in the \ACCESS directory on drive C, type C:\ACCESS\MSAU200.DLL.
 * 5) In the Destination box, select $(AppPath).
 * 6) Choose OK.
 * 7) Proceed through the Setup Wizard as normal.

Step 8: Call AreTablesAttached Function in Application's AutoExec Macro
In the Solutions sample application, the Autoexec macro calls the AreTablesAttached function. This function determines whether the table attachments are valid. If the attachments are not valid, the function prompts the user for the location of the attached tables. If the function returns True, the tables were successfully reattached. If the function returns False, the tables could not be found in the user-specified path and the database is closed.

The AutoExec macro from the SOLUTION.MDB database is listed below: <pre class="fixed_text">  Condition                 Action NOT AreTablesAttached  DoMenuItem OpenForm

Action Arguments --  DoMenuItem Menu Bar: Database Menu Name: File Command: Close Database OpenForm Form Name: Startup

<div class="references_section">