LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Need Help With ADO Recordset and Loop

Hello,

I have the following code, which works, but it drags.

What I need to do, is loop through each worksheet and if the name has
Detail in it, read in the policy number and then connect to another
datasource to lookup information based on this policy. Any suggestions
would be appreicated:

Dim cn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strConn As String
Dim strPolicyNumber As String
Dim wb As Workbook
Dim ws As Worksheet
Dim rng As Range
Dim i As Integer

Set wb = ActiveWorkbook
Set ws = wb.ActiveSheet

Set rng = Cells(Rows.Count, 1).End(xlUp)

' zzzzed out server information
strConn = "Driver={SQL Server};" & _
"Server=zzzzz;" & _
"Database=zzzzz;" & _
"Uid=izzzzz;" & _
"Pwd="

Set cn = New ADODB.Connection

cn.Open strConn

Set rst = New ADODB.Recordset

rst.Open "Select polnum, F_EntryDate From tblPolicyInformation", cn,
adOpenForwardOnly, adLockReadOnly, adCmdText

For Each ws In wb.Worksheets
If InStr(1, ws.Name, "Detail") 0 Then
ws.Select
ws.Range("I:I").Select
rst.MoveFirst
For i = rng.Row To 3 Step -1

rst.MoveFirst ' Make sure pojnter is at the top
strPolicyNumber = Cells(i, "B").Value
If strPolicyNumber < "" Then
rst.Find "polnum = '" & strPolicyNumber & "'" -
This is where a delay happens
If Not rst.EOF Then
ws.Cells(i, "I").Value = rst("F_EntryDate")
End If
End If
Next i
End If
Next ws

Thanks,
Brian

 
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
Connection Recordset Loop Problem with VBA - Help ina Excel Programming 2 May 12th 06 05:28 PM
Need ADO Recordset Help Mr B[_2_] Excel Programming 9 April 21st 06 04:51 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Problem adding charts using Do-Loop Until loop Chris Bromley[_2_] Excel Programming 2 May 23rd 05 01:31 PM
Type recordset/recordset? FlaviusFlav[_9_] Excel Programming 4 May 24th 04 12:16 PM


All times are GMT +1. The time now is 03:19 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"