Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
ina ina is offline
external usenet poster
 
Posts: 120
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default 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.
  #3   Report Post  
Posted to microsoft.public.excel.programming
ina ina is offline
external usenet poster
 
Posts: 120
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
ina ina is offline
external usenet poster
 
Posts: 120
Default GetConnection

Oupps Thank you :) little tired now



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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



  #7   Report Post  
Posted to microsoft.public.excel.programming
ina ina is offline
external usenet poster
 
Posts: 120
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"