ADT2: How to Modify Reattach NWIND Module in SOLUTION.MDB
ID: Q125434
|
The information in this article applies to:
-
Microsoft Access Developer's Toolkit, version 2.0
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.
- Import the sample code from SOLUTION.MDB.
- Add a user-defined type from the WZLIB.MDA file.
- Add declare functions from the WZLIB.MDA file.
- Modify the sample GetMDBName() function.
- Modify the sample GetMDBName2() function.
- Modify the sample AreTablesAttached() function.
- Add the MSAU200.DLL file to your application's Setup using the
Setup Wizard.
- 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
- With your database open, choose Import from the File menu.
- In the Data Source box, select Microsoft Access and then choose OK.
- In the File Name box, select SOLUTION.MDB and then choose OK.
- In the Object Type box, select Modules. In the Objects In
SOLUTION.MDB box, select Reattach NWIND and then choose the
Import button.
- When you are prompted "Successfully imported 'Reattach NWIND'"
choose OK.
- 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
- Modify the line as follows to make the Find Database dialog box modal:
OFN.hwndOwner = MSA_FindWindow("OMain", 0&)
- Search the GetMDBName() function for the following line:
OFN.szTitle = "Where is your NWIND.MDB?"
- Change the line so that it uses the name of your database instead of
NWIND.MDB.
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
- Modify the line to read:
Function GetMDBName2(gfni As GetFileNameInfo, ByVal fopen _
as Integer) As Long
- Search the GetMDBName2() function for the following line:
lRet = wlib_MSAU_GetFileName(gfni, fOpen)
- Modify the line as follows to reference the new type:
lRet = MSAU_GetFileName(gfni, fOpen)
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")
- Replace the Products table with the name of the appropriate table in
your attached database.
- Search for and replace all references to NWIND.MDB and SOLUTION.MDB.
Replace these references with your database names.
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:
- Start the Setup Wizard.
- Add your databases to the Files To Include list.
- Choose the Add File button.
- In the File Name box, type <drive>:\<access>\MSAU200.DLL where <drive> and <access> 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.
- In the Destination box, select $(AppPath).
- Choose OK.
- 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:
Condition Action
------------------------------------
NOT AreTablesAttached() DoMenuItem
OpenForm
Action Arguments
--------------------------
DoMenuItem
Menu Bar: Database
Menu Name: File
Command: Close Database
OpenForm
Form Name: Startup
REFERENCES
Microsoft Access Developer's Toolkit "Advanced Topics," version 2.0,
Chapter 2, "Creating a Custom Setup Program," pages 19-35
Microsoft Access "Building Applications," version 2.0, Chapter 1,
"Applications Basics," pages 17-19
Additional query words:
attach adt reattach Nwind re-link relink
Keywords : kbprg
Version : WINDOWS:2.0
Platform : WINDOWS
Issue type : kbhowto