Microsoft KB Archive/143039

= Calling Visual Basic 4.0 OLE Server from Microsoft Access 2.0 =

Article ID: 143039

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Enterprise Edition

-



This article was previously published under Q143039



SUMMARY
Visual Basic 4.0 allows you to not only build OLE Servers but build applications which can use them. Microsoft Access 2.0 is an OLE Automation Client application, therefore it can be used to call methods and properties from OLE servers created with Visual Basic 4.0. This article will describe the process of using OLE servers created by Visual Basic 4.0 with Access 2.0. The example will be using the OLE server example created in the Microsoft Knowledge Base article 129801, "How to Create and Use a Minimal OLE Automation Server."



MORE INFORMATION
Prior to following this example, make sure you have built the OLE Server discussed in 129801, and have built an EXE file.

Steps to Use a Visual Basic 4.0 OLE Server with Access 2.0
 Start Access 2.0, from the File menu select New Database and accept the default database, Db1.mdb. From the Access 2.0 database window, select the Module Tab. Now select the New button at the top of the database window to build a new Access Basic module.  Type the following code in the module. Function CallServer As Integer

Dim MyObj As Object

Set MyObj = CreateObject("Project1.Class1")

MsgBox MyObj.MyString MsgBox MyObj.MyFunction

End Function  Save this function, by selecting the File menu and choosing the Save item. Accept the default to save the module as Module1. You may now close the code window. From the Access database window, now select the Macro Tab. Then select the new button. We will now be able to write a macro which calls our Access Basic code. From the macro design screen, select Run code from the combo box under the Action column.</li> Now a textbox will appear at the bottom of this screen labeled as Function Name. Click on the text box, and a button with three dots will appear. Click on this button.</li> The Expression Builder dialog now appears. Double click on the functions folder in the lower-left corner of the dialog box.</li> You will see a sub folder of the functions folder labeled DB1, standing for the name of our database. Double-click this folder.</li> Select the paste button. The CallServer function will be pasted in as the parameter to the RunCode Macro. Select OK from the Expression Builder dialog box to close the dialog box.</li> Save this macro, by selecting the File menu and choosing the Save item. Accept the default to save the macro as Macro1. You may now close the macro window.</li> Select the macro in the Database window.</li> Select the run button to run the macro. When this function executes, you will get two message boxes. The first one will say, "Life is like a box of chocolates." The second one will say, "You never know what you're gonna get."</li></ol>

Additional query words: 4.00 vb4win text box

Keywords: KB143039

-

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

© Microsoft Corporation. All rights reserved.