Using the Print dialog box
The Print dialog box allows the user to specify the method of printing output. Users can specify the range of printed pages, print quality, number of copies, etc. This dialog box also displays information about currently installed printers and allows the user to configure or reinstall a new default printer.
Note that this dialog box does not actually send data to the printer. It allows the user to specify how to print data. You must write code to print the data in the selected format.
For more information about printing data, see Chapter 12, "Working with Text and Graphics." At run time, after the user makes a selection in the Print dialog box, the following properties will contain information about the user's options.
To display the Print dialog box
1. Set the desired default settings for the dialog box by setting the appropriate Print dialog box properties. For example, to display 2 in the Number of Copies box when the dialog box is displayed, set the Copies property to 2:
CommonDialog1.Copies=2
2. Use the ShowPRinter method to display the "Print" dialog box.
When the user clicks the Command1 command button, the following code displays the Print dialog box:
PrivateSubCommand1_Click()
DimBeginPage,EndPage,NumCopies,Orientation.i
'Set Cancel to True.
CommonDialog1.CancelError=True
OnErrorGoToErrHandler
'Display the "Print" dialog box.
CommonDialog1.ShowPrinter
'Get the user selected value from the dialog box.
BeginPage=CommonDialog1.FromPage
EndPage=CommonDialog1.ToPage
NumCopies=CommonDialog1.Copies
Orientation=CommonDialog1.Orientation
Fori=1toNumCopies
'Place code here to send data to the printer.
Next
NxitSub
ErrHandler:
'The user pressed the "Cancel" button.
ExitSub
EndSub
Note that if you set the PrinterDefault property to True, you can print on the VisualBasicPrinter object. In addition, when the PrinterDefault property is True, all changes made in the "Settings" section of the "Print" dialog box will change the printer settings in the user's "Printer" settings.
Use the ShowHelp method to display help files
Help files can be displayed using the ShowHelp method of the CommonDialog control.
To display a help file using the ShowHelp method
1. Set the HelpCommand and HelpFile properties.
2. Use the ShowHelp method to display the specified help file.
When the "Command1" command button is clicked, the following code displays the specified help file:
PrivateSubCommand1_Click()
'Set Cancel to True.
CommonDialog1.CancelError=True
OnErrorGoToErrHandler
'Set the HelpCommand property
CommonDialog1.HelpCommand=cdlHelpForceFile
'Specify the help file.
CommonDialog1.HelpFile=c:/Windows/Cardfile.hlp
'Show the Windows help engine.
CommonDialog1.ShowHelp
ExitSub
ErrHandler:
'The user pressed the "Cancel" button.
ExitSub
EndSub
For more information about the help file that displays the common dialog box control, see "Visual Basic 6.0 Language Reference Manual" "HelpCommand Property", "HelpFile Property" and "ShowHelp Method".
Using the Data control
The inherent Data control implements data access by using Microsoft's Jet database engine - the same database engine used by Microsoft Access. This technology provides users with seamless access to many standard database formats and allows users to create data recognition applications without writing any code. This inherent Data control is best suited for smaller (desktop) databases such as Access and ISAM databases.
You can use this built-in Data control to create applications that display, edit, and update information from a variety of existing databases. These databases include Microsoft Access, Btrieve, dBASE, Microsoft FoxPro and Paradox. You can also use this control to access Microsoft Excel, Lotus 1-2-3, and standard ASCII text files just like accessing a real database. In addition, the Data control can also access and operate remote Open Database Connectivity (ODBC) databases, such as Microsoft SQL Server and Oracle.
Note that both the Data control and the RemoteData control are included in Visual Basic to provide backward compatibility. However, due to the wider adaptability of ActiveX Data Objects (ADO), it is recommended to use the ADOData control to create new database applications. See "Using the ADOData Control" for details.
The Data control, RemoteData control, and ADOData control are conceptually similar: all three are "data controls" that connect a data source to a data-bound control. All three also share the same look and feel—a set of four buttons that allow users to go directly to the beginning of the record set, the end of the record set, and scroll forward or backward through the record set.
Create a simple database application using the Data control
To create a simple database application using the Data control
1. Place a Data control on the form. The Data control is an intrinsic control and is therefore always available.
2. Click and select the Data control, and press the F4 key to display the "Properties" window.
3. In the Properties window, set the Connection property to the database type you want to use.
4. In the Properties window, set the DatabaseName property to the file or directory name of the database you want to connect to.
5. In the Properties window, set the RecordSource property to the name of the database table you want to access.
6. Place a text box control on the form.
7. Click and select the TextBox control, and set the "Data Source" property to the Data control in its "Properties" window.
8. In the Properties window, set the Data Field property to the name of the field in this database that you want to view or modify.
9. Repeat steps 6, 7, and 8 for each other field you want to access.
10. Press F5 key to run this application.
Set data-related properties of the Data control
The following data-related properties can be set at design time. This list gives a logical order for setting these properties:
Note that database technology is a complex science, and the following suggestions are not meant to be used as rules.
1.RecordsetType—The RecordsetType attribute determines whether the recordset is a table, a dynamic set (dynaset), or a snapshot. This selection affects which recordset properties are available. For example, snapshot type recordsets have more restrictions than dynaset recordsets.
2.DefaultType—The DefaultType attribute specifies whether the JET workspace or the ODBCDirect workspace is used.
3.DefaultCursorType—The DefaultCursorType attribute determines the position of the cursor. You can use the ODBC driver to determine the cursor position, or specify a server or ODBC cursor. The DefaultCursorType property is valid only when using the ODBCDirect workspace.
4.Exclusive—Determines whether the data is for a single-user environment or a multi-user environment.
5.Options—This attribute determines the characteristics of the recordset. For example, in a multi-user environment, you can set the Options property to disable changes made by others.
6.BOFAction, EOFAction—These two properties determine the behavior of this control when it is located at the beginning or end of the cursor. Possible choices include staying at the beginning or end, moving to the first or last record, or adding a new record (only at the end).
->