SAMPLE: DAO_OCX.EXE ActiveX Control Uses DAO to Query DatabaseID: Q152116
|
This sample demonstrates querying and displaying the result of the query
using MFC's CDao classes from an ActiveX control (OLE Control.)
The DaoOcx control utilizes a saved query in the CUSTOMER.MDB database
provided with the sample. This database consists of phone numbers and their
associated addresses. Additionally, there may be several people at each
address and each individual may be associated with a note.
When the FindNumber() method is called from the client, it queries the
database for the currently-entered phone number using the saved query
ByPhone, retrieves the data, and then populates the fields with the
address. It also populates a List Box with the names of the people at that
address. Once the user selects one of the names, it places the note
associated with that individual, if there is one, in the note edit control,
and then fires an event.
The client application should call the ConnectDataBase method initially and
must call the CleanUp method prior to shutdown. In the Visual Basic portion
of this sample, the ConnectDataBase call is made in the Form's Load
procedure and the CleanUp call is made in the Form's Terminate procedure.
The database name and the name of the saved query are properties of the
control and can be set. If the property sheet is used to set the
properties, then validation is done. No validation is performed if the
properties are not entered using the property sheet provided.
The following file is available for download from the Microsoft
Software Library:
~ Dao_ocx.exeFor more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
Q119591 How to Obtain Microsoft Support Files from Online Services
Once you have unzipped the file, you should have the actual database,
CUSTOMER.MDB, that includes the saved query ByPhone. This database was
created using Access 2.0 and may also be accessed using Access 95. Also
included are the files for the control and a Visual Basic 4.0 (32- bit)
project and form that demonstrates how to use the control. You must build
and register the control, and then set the location of the CUSTOMER.MDB
file in the DaoOcx control on the Visual Basic form before running the
Visual Basic client.
Once the client is running, enter one of the following phone numbers
(555) 555-5555, (526) 874-4632 or (816) 547-1234. Click the Find button to
see some sample data. Once the names are visible, select one and see the
note associated with that individual. You will also see a message box
caused by an event fired from the control indicating that the data is
complete.
The control uses a CDaoRecordSet derived class that is used to query
the database. This class can be generated by hand, or you can use the
AppWizard to create it as follows:
Additional query words: 4.10
Keywords : kbsample CodeSam
Version : 4.10
Platform : NT WINDOWS
Issue type :
Last Reviewed: July 28, 1999