Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default Macro to call database table needs to process faster

Hello all -

I have a macro which calls out to a SQL database table and populates
into an Excel sheet. There are 1700 records in the SQL table, but it
is taking close to 2 minutes to populate the records back into Excel.
The slowdown seems to be in the loop that was created.

Any ideas on how to this macro can process faster?


Private Sub Workbook_Open()
Dim cnn1 As ADODB.Connection
Dim runspcmd As ADODB.Command
Dim x As Integer

Set cnn1 = New ADODB.Connection
cnn1.ConnectionString = "Provider=sqloledb;Data
Source=000.00.000.000;Initial Catalog=brdatadb;User
Id=stuff;Password=stuff;"
cnn1.ConnectionTimeout = 300

cnn1.Open

Set runspcmd = New ADODB.Command
runspcmd.ActiveConnection = cnn1
runspcmd.CommandTimeout = 120

x = 0

Set rs = New ADODB.Recordset
rs.CursorType = adOpenDynamic
rs.CursorLocation = adUseClient

runspcmd.CommandText = "select vendor_code, vendor_name from vendor
order by vendor_name "
rs.Open runspcmd

For x = 1 To rs.RecordCount

If Not rs.EOF Then
Me.Worksheets.Item(2).Cells(x + 1, 1).Value = rs("vendor_name")
Me.Worksheets.Item(2).Cells(x + 1, 2).Value = rs("vendor_code")

End If
rs.MoveNext
Next

rs.Close
cnn1.Close
End Sub


Thanks for any assistance!
Dan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default Macro to call database table needs to process faster

runspcmd.CommandText = "select vendor_name, vendor_code from " & _
" vendor order by vendor_name "
rs.Open runspcmd

if not rs.eof then
Me.Worksheets.Item(2).range("A2").copyfromrecordse t rs
end if

--
Tim Williams
Palo Alto, CA


"Dan" wrote in message oups.com...
Hello all -

I have a macro which calls out to a SQL database table and populates
into an Excel sheet. There are 1700 records in the SQL table, but it
is taking close to 2 minutes to populate the records back into Excel.
The slowdown seems to be in the loop that was created.

Any ideas on how to this macro can process faster?


Private Sub Workbook_Open()
Dim cnn1 As ADODB.Connection
Dim runspcmd As ADODB.Command
Dim x As Integer

Set cnn1 = New ADODB.Connection
cnn1.ConnectionString = "Provider=sqloledb;Data
Source=000.00.000.000;Initial Catalog=brdatadb;User
Id=stuff;Password=stuff;"
cnn1.ConnectionTimeout = 300

cnn1.Open

Set runspcmd = New ADODB.Command
runspcmd.ActiveConnection = cnn1
runspcmd.CommandTimeout = 120

x = 0

Set rs = New ADODB.Recordset
rs.CursorType = adOpenDynamic
rs.CursorLocation = adUseClient

runspcmd.CommandText = "select vendor_code, vendor_name from vendor
order by vendor_name "
rs.Open runspcmd

For x = 1 To rs.RecordCount

If Not rs.EOF Then
Me.Worksheets.Item(2).Cells(x + 1, 1).Value = rs("vendor_name")
Me.Worksheets.Item(2).Cells(x + 1, 2).Value = rs("vendor_code")

End If
rs.MoveNext
Next

rs.Close
cnn1.Close
End Sub


Thanks for any assistance!
Dan



  #3   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default Macro to call database table needs to process faster

On Feb 28, 4:47 pm, "Tim Williams" <timjwilliams at gmail dot com
wrote:
runspcmd.CommandText = "select vendor_name, vendor_code from " & _
" vendor order by vendor_name "
rs.Open runspcmd

if not rs.eof then
Me.Worksheets.Item(2).range("A2").copyfromrecordse t rs
end if

--
Tim Williams
Palo Alto, CA



"Dan" wrote in ooglegroups.com...
Hello all -


I have a macro which calls out to a SQL database table and populates
into an Excel sheet. There are 1700 records in the SQL table, but it
is taking close to 2 minutes to populate the records back into Excel.
The slowdown seems to be in the loop that was created.


Any ideas on how to this macro can process faster?


Private Sub Workbook_Open()
Dim cnn1 As ADODB.Connection
Dim runspcmd As ADODB.Command
Dim x As Integer


Set cnn1 = New ADODB.Connection
cnn1.ConnectionString = "Provider=sqloledb;Data
Source=000.00.000.000;Initial Catalog=brdatadb;User
Id=stuff;Password=stuff;"
cnn1.ConnectionTimeout = 300


cnn1.Open


Set runspcmd = New ADODB.Command
runspcmd.ActiveConnection = cnn1
runspcmd.CommandTimeout = 120


x = 0


Set rs = New ADODB.Recordset
rs.CursorType = adOpenDynamic
rs.CursorLocation = adUseClient


runspcmd.CommandText = "select vendor_code, vendor_name from vendor
order by vendor_name "
rs.Open runspcmd


For x = 1 To rs.RecordCount


If Not rs.EOF Then
Me.Worksheets.Item(2).Cells(x + 1, 1).Value = rs("vendor_name")
Me.Worksheets.Item(2).Cells(x + 1, 2).Value = rs("vendor_code")


End If
rs.MoveNext
Next


rs.Close
cnn1.Close
End Sub


Thanks for any assistance!
Dan- Hide quoted text -


- Show quoted text -


Perfect!! Thanks so much for helping out this rookie.

Dan

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can my macro run faster ? Roger[_2_] New Users to Excel 12 October 26th 09 12:57 PM
Macro to importing a text file to populate a database/table TKM New Users to Excel 1 December 14th 06 06:39 PM
Can faster CPU+larger/faster RAM significantly speed up recalulati jmk_li Excel Discussion (Misc queries) 2 September 28th 05 10:24 AM
How to count process running time ( process not finished) miao jie Excel Programming 0 January 13th 05 09:23 AM
faster macro _______Tim_______ Excel Programming 6 August 28th 03 03:01 PM


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

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

About Us

"It's about Microsoft Excel"