GetConnection

I

ina

Hello guys,

I have this connection how to get several recordset from this
connection

Sub GetconnectionADOBD()

Dim cndb As ADODB.Connection, cndb1 As ADODB.Connection


Set cndb = New ADODB.Connection
Set cndb1 = New ADODB.Connection


cndb.ConnectionString = CONNECTION
cndb.Open

If cndb.State = adStateOpen Then
End If


End Sub

How can I define my Sub. I would to call this function and they ask for
a connection

Sub recordsetMacro1()


Sub RecordSetMacro2 ()
Ina
 
A

AA2e72E

Nor sure what the problem is:

If you want recordsets (DQL subset of SQL) only, use recordset objects only:

set RS1 = CreateObject("ADODB.Recordset")
RS1.Open "SELECT * FROM MYTABLE", "MYConnectionString"
RS1.Open "SELECT * FROM MYTABLE2", "MYConnectionString"

i.e you do not need a connection object to open a recordset, just a
connection string.

IF you want to use a connection object:

SET CN = CreteObject("ADODB.Connection")
CN.Open "MyconnectionString")

SET RS = CreteObject("ADODB.RecordSet")
RS1.Open "your SQL statement", CN
RS2.Open "your SQL statement", CN

With the latter approach, you have 2 objects to manage.
 
I

ina

Thanks I would like to do like this

Function GetConnectionADOBD( ) As ADOBD.Connection ' I have an error
here


Dim cndb As ADODB.Connection, cndb1 As ADODB.Connection

cndb.ConnectionString = "CONNECTION"
cndb.Open

cndb2 = GetConnectionADODB

End Function

Sub GetRecordSet ()

Dim cndb As ADODB.Connection
Dim rsAs ADODB.Recordset
Dim strSQL As String

Set cndb = New ADODB.Connection
Set rs = New ADODB.Recordset

cndb = GetConnectionADOBD 'from my function

......

End Sub
 
A

AA2e72E

Should

Function GetConnectionADOBD( ) As ADOBD.Connection

be

Function GetConnectionADOBD( ) As ADODB.Connection

DB not BD
 
T

Tim Williams

Put "Option Explicit" at the top of *every* code module. It will highlight a lot of your problems.

Function GetConnectionADODB( ) As ADODB.Connection

Dim cndb As new ADODB.Connection

cndb.ConnectionString = "CONNECTION"
cndb.Open
set GetConnectionADODB = cndb

End Function
 
I

ina

thanks a lot guys now seems that I understood much better. :)
my problem is more how to call function with VBA with set such as set
getConnectionADODB = cndb, but now I thing I understood.

Ina
 

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