The dataenvironment opens itself when your form loads. Try closing it before
switching to another provider. Below is a code snippet showing how that is
done. The dataenvironment is named devShowTime and the only connection
object is named dcnShowTime. Change them to your names or pass them as
parameters to the routine if you have more than one.
Private Sub DEvClose()
Dim X As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
On Error Resume Next
For Each cmd In devShowTime.Commands
Set X = cmd.ActiveConnection
If (X.State = adStateOpen) Then Set X = Nothing
Next
For Each rst In devShowTime.Recordsets
Set X = rst.ActiveConnection
If (X.State = adStateOpen) Then X.Close
If (rst.State = adStateOpen) Then rst.Close
Set X = Nothing
Next
If (devShowTime.dcnShowTime.State = adStateOpen) Then
devShowTime.dcnShowTime.Close
Exit Sub
BigProblem:
MsgBox Err.Description
End Sub
Stefan
Quote:> I am trying to write a application that is switchable between Access and
SQL
> at run time.
> When I execute the following code snippet at init I get a run time error:
> DataEnvironment1.TestConnection.Provider = "SQLOLEDB.1"
> The error is:
> Run-time error '3220': Supplied provider is different from the one
> already in use.
> The connection is not already open so I don't understand the reason for
the
> error. I know I can create the objects all in code and not have this
> problem but I want to design the forms with the visual instance of the
> obect.
> TIA
> Sean Smith