Microsoft KB Archive/195982

= HOWTO: Set the Connection Prompt Behavior of DataEnvironment =

Article ID: 195982

Article Last Modified on 3/14/2005

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q195982



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.</li></ol>

<div class="references_section">