PC Review


Reply
Thread Tools Rate Thread

calls to extract data from an open database

 
 
Spike
Guest
Posts: n/a
 
      19th Apr 2010
I have a workbook that on the “open” event connects to an Oracle database
using ADO, this works fine.

I need to code various calls to the data base to run several queries. How
do I achieve this? Do I have to repeat the ADO connection string to the
database complete with password etc; I am sure this is not necessary.

Any code will be very gratefully received.

--
with kind regards

Spike
 
Reply With Quote
 
 
 
 
RB Smissaert
Guest
Posts: n/a
 
      19th Apr 2010
The usual way to handle this is have a Public or Private ADO connection
object so you can set that up once and
keep it alive till you don't need it anymore.
So for example:

Option Explicit
Public oADOConn As ADODB.Connection

Sub OpenConnection(strConnString As String, _
strUserName As String, _
strPassWord As String)

If oADOConn Is Nothing Then
Set oADOConn = New ADODB.Connection
End If

If oADOConn.State = 0 Then
oADOConn.Open strConnString, strUserName, strPassWord
End If

End Sub


RBS


"Spike" <(E-Mail Removed)> wrote in message
news7EE54B2-88F2-46BE-B80B-(E-Mail Removed)...
>I have a workbook that on the “open” event connects to an Oracle database
> using ADO, this works fine.
>
> I need to code various calls to the data base to run several queries. How
> do I achieve this? Do I have to repeat the ADO connection string to the
> database complete with password etc; I am sure this is not necessary.
>
> Any code will be very gratefully received.
>
> --
> with kind regards
>
> Spike


 
Reply With Quote
 
Spike
Guest
Posts: n/a
 
      19th Apr 2010
Thank you for that. Does the connection stay open to the workbook until it
is closed; so the while the connection is open one can run a completely
different macro and then run a macro that will extract data from the
database. If so is the code something like as below or does one have to
provide user name and password every time?

With oADOConn
.CommandText = "SELECT PB_RATES.COB_DATE, PB_RATES.MAT_BIN_START,
PB_RATES.MAT_BIN_END," _
& "PB_RATES.MAT_RATE_LOAN" _
& " FROM OPS$ORA_ADMIN.PB_RATES PB_RATES" _
& " WHERE (PB_RATES.COB_DATE={ts '" & strRateDate & "'})"

..CommandType = adCmdText

Set RS = New ADODB.Recordset
RS.CursorType = adOpenStatic
RS.LockType = adLockReadOnly
Set RS.Source = CM

bolDataBaseErr = True 'changed to false if opens RS correctly

RS.Open
RS.MoveFirst

Etc etc

--
with kind regards

Spike


"RB Smissaert" wrote:

> The usual way to handle this is have a Public or Private ADO connection
> object so you can set that up once and
> keep it alive till you don't need it anymore.
> So for example:
>
> Option Explicit
> Public oADOConn As ADODB.Connection
>
> Sub OpenConnection(strConnString As String, _
> strUserName As String, _
> strPassWord As String)
>
> If oADOConn Is Nothing Then
> Set oADOConn = New ADODB.Connection
> End If
>
> If oADOConn.State = 0 Then
> oADOConn.Open strConnString, strUserName, strPassWord
> End If
>
> End Sub
>
>
> RBS
>
>
> "Spike" <(E-Mail Removed)> wrote in message
> news7EE54B2-88F2-46BE-B80B-(E-Mail Removed)...
> >I have a workbook that on the “open” event connects to an Oracle database
> > using ADO, this works fine.
> >
> > I need to code various calls to the data base to run several queries. How
> > do I achieve this? Do I have to repeat the ADO connection string to the
> > database complete with password etc; I am sure this is not necessary.
> >
> > Any code will be very gratefully received.
> >
> > --
> > with kind regards
> >
> > Spike

>
> .
>

 
Reply With Quote
 
RB Smissaert
Guest
Posts: n/a
 
      19th Apr 2010
> Does the connection stay open to the workbook until it is closed?
Yes, unless you close it actively with oADOConn.Close or Set oADOConn =
Nothing or if you close the Workbook.

> If so is the code something like as below?

Yes, connection has been set up once already and stays alive.


RBS


"Spike" <(E-Mail Removed)> wrote in message
news:30087751-AAF3-482E-86A9-(E-Mail Removed)...
> Thank you for that. Does the connection stay open to the workbook until
> it
> is closed; so the while the connection is open one can run a completely
> different macro and then run a macro that will extract data from the
> database. If so is the code something like as below or does one have to
> provide user name and password every time?
>
> With oADOConn
> .CommandText = "SELECT PB_RATES.COB_DATE, PB_RATES.MAT_BIN_START,
> PB_RATES.MAT_BIN_END," _
> & "PB_RATES.MAT_RATE_LOAN" _
> & " FROM OPS$ORA_ADMIN.PB_RATES PB_RATES" _
> & " WHERE (PB_RATES.COB_DATE={ts '" & strRateDate & "'})"
>
> .CommandType = adCmdText
>
> Set RS = New ADODB.Recordset
> RS.CursorType = adOpenStatic
> RS.LockType = adLockReadOnly
> Set RS.Source = CM
>
> bolDataBaseErr = True 'changed to false if opens RS correctly
>
> RS.Open
> RS.MoveFirst
>
> Etc etc
>
> --
> with kind regards
>
> Spike
>
>
> "RB Smissaert" wrote:
>
>> The usual way to handle this is have a Public or Private ADO connection
>> object so you can set that up once and
>> keep it alive till you don't need it anymore.
>> So for example:
>>
>> Option Explicit
>> Public oADOConn As ADODB.Connection
>>
>> Sub OpenConnection(strConnString As String, _
>> strUserName As String, _
>> strPassWord As String)
>>
>> If oADOConn Is Nothing Then
>> Set oADOConn = New ADODB.Connection
>> End If
>>
>> If oADOConn.State = 0 Then
>> oADOConn.Open strConnString, strUserName, strPassWord
>> End If
>>
>> End Sub
>>
>>
>> RBS
>>
>>
>> "Spike" <(E-Mail Removed)> wrote in message
>> news7EE54B2-88F2-46BE-B80B-(E-Mail Removed)...
>> >I have a workbook that on the “open” event connects to an Oracle
>> >database
>> > using ADO, this works fine.
>> >
>> > I need to code various calls to the data base to run several queries.
>> > How
>> > do I achieve this? Do I have to repeat the ADO connection string to
>> > the
>> > database complete with password etc; I am sure this is not necessary.
>> >
>> > Any code will be very gratefully received.
>> >
>> > --
>> > with kind regards
>> >
>> > Spike

>>
>> .
>>


 
Reply With Quote
 
Spike
Guest
Posts: n/a
 
      19th Apr 2010
thank you very much for that i will code it up tomorrow. i am most grateful.
--
with kind regards

Spike


"RB Smissaert" wrote:

> > Does the connection stay open to the workbook until it is closed?

> Yes, unless you close it actively with oADOConn.Close or Set oADOConn =
> Nothing or if you close the Workbook.
>
> > If so is the code something like as below?

> Yes, connection has been set up once already and stays alive.
>
>
> RBS
>
>
> "Spike" <(E-Mail Removed)> wrote in message
> news:30087751-AAF3-482E-86A9-(E-Mail Removed)...
> > Thank you for that. Does the connection stay open to the workbook until
> > it
> > is closed; so the while the connection is open one can run a completely
> > different macro and then run a macro that will extract data from the
> > database. If so is the code something like as below or does one have to
> > provide user name and password every time?
> >
> > With oADOConn
> > .CommandText = "SELECT PB_RATES.COB_DATE, PB_RATES.MAT_BIN_START,
> > PB_RATES.MAT_BIN_END," _
> > & "PB_RATES.MAT_RATE_LOAN" _
> > & " FROM OPS$ORA_ADMIN.PB_RATES PB_RATES" _
> > & " WHERE (PB_RATES.COB_DATE={ts '" & strRateDate & "'})"
> >
> > .CommandType = adCmdText
> >
> > Set RS = New ADODB.Recordset
> > RS.CursorType = adOpenStatic
> > RS.LockType = adLockReadOnly
> > Set RS.Source = CM
> >
> > bolDataBaseErr = True 'changed to false if opens RS correctly
> >
> > RS.Open
> > RS.MoveFirst
> >
> > Etc etc
> >
> > --
> > with kind regards
> >
> > Spike
> >
> >
> > "RB Smissaert" wrote:
> >
> >> The usual way to handle this is have a Public or Private ADO connection
> >> object so you can set that up once and
> >> keep it alive till you don't need it anymore.
> >> So for example:
> >>
> >> Option Explicit
> >> Public oADOConn As ADODB.Connection
> >>
> >> Sub OpenConnection(strConnString As String, _
> >> strUserName As String, _
> >> strPassWord As String)
> >>
> >> If oADOConn Is Nothing Then
> >> Set oADOConn = New ADODB.Connection
> >> End If
> >>
> >> If oADOConn.State = 0 Then
> >> oADOConn.Open strConnString, strUserName, strPassWord
> >> End If
> >>
> >> End Sub
> >>
> >>
> >> RBS
> >>
> >>
> >> "Spike" <(E-Mail Removed)> wrote in message
> >> news7EE54B2-88F2-46BE-B80B-(E-Mail Removed)...
> >> >I have a workbook that on the “open” event connects to an Oracle
> >> >database
> >> > using ADO, this works fine.
> >> >
> >> > I need to code various calls to the data base to run several queries.
> >> > How
> >> > do I achieve this? Do I have to repeat the ADO connection string to
> >> > the
> >> > database complete with password etc; I am sure this is not necessary.
> >> >
> >> > Any code will be very gratefully received.
> >> >
> >> > --
> >> > with kind regards
> >> >
> >> > Spike
> >>
> >> .
> >>

>
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract data from another database Montu Microsoft Excel Worksheet Functions 2 22nd Feb 2008 01:20 AM
Extract data from database Montu Microsoft Excel Worksheet Functions 8 19th Feb 2008 01:55 PM
HELP: VBA Code to extract data from an SQL Server database and put it into Access Database Clinton M James Microsoft Excel Programming 1 8th Oct 2007 12:44 AM
Manipulation of Data extract from Access Database =?Utf-8?B?Q2hhc2U=?= Microsoft Excel Misc 2 19th Jul 2007 07:42 AM
Extract Data from an Access Database in to Excel John Microsoft Excel Programming 2 2nd Jan 2006 12:18 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:44 PM.