Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / SQL Server / ADP / August 2005

Tip: Looking for answers? Try searching our database.

ADP equivalent for CurrentDB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter Wone - 13 Aug 2005 07:02 GMT
I realise that CurrentDb returns Nothing because there is no current Jet
database in an ADP. So how does one get a reference to the default database
connection? In bound forms I've been using Me.Recordset.ActiveConnection but
in an unbound form this doesn't work for fairly obvious reasons.
Steve Jorgensen - 13 Aug 2005 07:48 GMT
>I realise that CurrentDb returns Nothing because there is no current Jet
>database in an ADP. So how does one get a reference to the default database
>connection? In bound forms I've been using Me.Recordset.ActiveConnection but
>in an unbound form this doesn't work for fairly obvious reasons.

As I recall, it's CurrentProject.Connection
steel - 24 Aug 2005 07:33 GMT
I use this template for recordsets, works well;

Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim strMsg As String

'SQL_Connection
On Error GoTo <function_name>_Error

conn.Open CurrentProject.Connection
Set cmd.ActiveConnection = conn

strSQL = <insert SQL TExt>

cmd.CommandText = strSQL
cmd.CommandType = adCmdText
Set rs = cmd.Execute

If rs.State = adStateClosed Then
 'no connection made
 Goto <function_name>_error
else
 <Connection OK - carry out function>
End if

<function_name>_Exit:
 Set rs = Nothing
 Set cmd = Nothing
 conn.Close
 Set conn = Nothing
 Exit Sub

<function_name>_Error:
 strMsg = "ERROR: " & Err.Description
 If MsgBox(strMsg, vbCritical, "Error:") = vbOK Then
 End If
 Resume <function_name>_Exit
Signature

Regards,

Alan

> >I realise that CurrentDb returns Nothing because there is no current Jet
> >database in an ADP. So how does one get a reference to the default database
> >connection? In bound forms I've been using Me.Recordset.ActiveConnection but
> >in an unbound form this doesn't work for fairly obvious reasons.
>
> As I recall, it's CurrentProject.Connection
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.