HOWTO: Set the Connection Prompt Behavior of DataEnvironment
ID: Q195982
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0
SUMMARY
When using the DataEnvironment in Visual Basic 6.0, it is not possible to
set the prompting behavior at design-time. This property is set to
adPromptComplete by default. You might want to change this property so that a
prompt is not displayed when establishing a connection to a database. To do
this you must set the "Prompt" property of the DataEnvironment at run-time.
MORE INFORMATION
The prompt property of the DataEnvironment can be set using the following
syntax:
DataEnvironment.Connection1.Properties("Prompt") = adPromptNever
There are four possible values to specify here:
- adPromptAlways (1)
- adPromptComplete (2)
- adPromptCompleteRequired (3)
- adPromptNever (4)
Following are the steps to create a Visual Basic project that illustrates how
to use this property:
- Create a Standard EXE project in Visual Basic. Form1 is created by
default.
- Add a CommandButton to the default form.
- Add a DataEnvironment to the project.
- From the DataEnvironment window, right-mouse click on Connection1 and
select Properties.
- Select the Microsoft OLEDB Provider for ODBC Drivers. Click Next and
configure the second tab so that the connection will point to a valid
Database using either an existing DSN or a connection string.
- Add the following code to the default form:
Private Sub Command1_Click()
Debug.Print DataEnvironment1.Connection1.Properties("Prompt")
DataEnvironment1.Connection1.Open
End Sub
Private Sub Form_Load()
DataEnvironment1.Connection1.Properties("Prompt") = adPromptAlways.
' Uncomment this line to suppress the prompt dialog:
' DataEnvironment1.Connection1.Properties("Prompt") = adPromptNever.
End Sub
- Run the project and click the CommandButton. Note that a prompt is
displayed when you try to connect to the database. Uncomment the line of
code in the Form_Load() event that sets the prompt to adPromptNever and comment out the code that sets the prompt property to adPromptAlways. Run the code again and note that this time no prompt is displayed.
© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Mike Ruthruff, Microsoft Corporation
REFERENCES
Hitchhiker's Guide to Visual Basic and SQL Server (sixth edition)
Visual Basic 6.0 Online Help
Additional query words:
Keywords : kbVBp600 kbDataEnv kbGrpVBDB
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbhowto