buggseywork
Programmer
Hi;
I have a VBA macro that has to access the database at different times while it is doing its work. Every time the connection is requested the login screen will be shown in order for the user to log in and validate the connection. This is the way the AS/400 client access driver operates as far as I know. What I would like to do is to connect to the database and use this connection every time I want to do some work with the database thus eliminating the need to connect every time. Is this possible? Anyone have any suggestions on this?
Here is the connection function I have written and it does produce a valid connection (Pending a good log in of course) but I cannot use it in the Sub it is called from for some reason. I get Object required error. I know I must be using the wrong syntax or something... shouldn't a reference to that object be passed back to the callling sub?
HELP!!!!
here is the connection function I have written
Function GetCon(DataSource As String)
On Error GoTo ErrorHandler
Dim oConn As ADODB.Connection
Dim sConn As String
sConn = "Provider='IBMDA400';Data Source='" & DataSource & "';"
Set oConn = New ADODB.Connection
oConn.Open sConn
' this just checks the sate of the connection...
If GetState(oConn.State) = "adStateClosed" Then
ValidCon = Null
GoTo EndCon
End If
EndCon:
GetCon = oConn
Exit Function ' Exit Sub to avoid error handler.
' Close the connection.
' oConn.Close
' Set oConn = Nothing
ErrorHandler: ' Error-handling routine.
Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox Msg, vbInformation, "Error"
Resume Next ' Resume execution at same line that caused the error.
End Function
any help wouldbe appreciated...
best regards;
Bugs
I have a VBA macro that has to access the database at different times while it is doing its work. Every time the connection is requested the login screen will be shown in order for the user to log in and validate the connection. This is the way the AS/400 client access driver operates as far as I know. What I would like to do is to connect to the database and use this connection every time I want to do some work with the database thus eliminating the need to connect every time. Is this possible? Anyone have any suggestions on this?
Here is the connection function I have written and it does produce a valid connection (Pending a good log in of course) but I cannot use it in the Sub it is called from for some reason. I get Object required error. I know I must be using the wrong syntax or something... shouldn't a reference to that object be passed back to the callling sub?
HELP!!!!
here is the connection function I have written
Function GetCon(DataSource As String)
On Error GoTo ErrorHandler
Dim oConn As ADODB.Connection
Dim sConn As String
sConn = "Provider='IBMDA400';Data Source='" & DataSource & "';"
Set oConn = New ADODB.Connection
oConn.Open sConn
' this just checks the sate of the connection...
If GetState(oConn.State) = "adStateClosed" Then
ValidCon = Null
GoTo EndCon
End If
EndCon:
GetCon = oConn
Exit Function ' Exit Sub to avoid error handler.
' Close the connection.
' oConn.Close
' Set oConn = Nothing
ErrorHandler: ' Error-handling routine.
Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox Msg, vbInformation, "Error"
Resume Next ' Resume execution at same line that caused the error.
End Function
any help wouldbe appreciated...
best regards;
Bugs