OpenConnection don't Work

A

Antonio Ortiz

Client: Access 2000
Server: MSDE 1.0

Error: "Automation error", "Operation is not allowed when the object is
open.".

My function open an connection in code, but OpenConnection method (of
proyect) don't work. (Code is below)

thanks


Antonio Ortiz Ramirez
asesor en sistemas
(e-mail address removed)
www.aortiz.net
www.progvisual.com



Function ConnectProy() As Long
Dim C As String
Dim Cnx As New ADODB.Connection

On Error Resume Next
C = "PROVIDER=SQLOLEDB" & _
";DATA SOURCE=miservidor.dns2go.com" & _
";INITIAL CATALOG=midb" & _
";USER ID=sa" & _
";PASSWORD=" & _
";Network Library=DBMSSOCN"
Cnx.Open C 'Connection Ok
If (Err = 0) Then
Application.CurrentProject.OpenConnection C 'This say Error
If (Err = 0) Then
MsgBox "Connect ok", vbOKOnly + vbInformation, "Hello"
LeeParametros
Else
MsgBox "Error in connection " & vbNewLine & _
Err & ": " & Error, vbOKOnly + vbCritical, "Not connect"
End If
'Application.CurrentProject.Connection.Open C
Else
MsgBox "Error in connection " & vbNewLine & _
Err & ": " & Error, vbOKOnly + vbCritical, "Not connect"
End If
Cnx.Close
Set Cnx = Nothing
End Function
 
C

Chad Doyle

The connection is already open. Try CurrentProject.ActiveConnection
instead.

Set C = CurrentProject.ActiveConnection

Chad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top