![]() |
GetConnection
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 |
GetConnection
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. |
GetConnection
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 |
GetConnection
Should Function GetConnectionADOBD( ) As ADOBD.Connection be Function GetConnectionADOBD( ) As ADODB.Connection DB not BD "ina" wrote: 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 |
GetConnection
Oupps Thank you :) little tired now
|
GetConnection
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 -- Tim Williams Palo Alto, CA "ina" wrote in message ups.com... 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 |
GetConnection
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 |
All times are GMT +1. The time now is 09:18 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com