Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default how do i loop in a access search

I can get my data out of access but i only find the first record.
Most of the time there ar two records in acces that i need to find.
I use the folloing code.

With rs
' open the recordset
'.Open TableName, cn, adOpenStatic, adLockOptimistic, adCmdTable
' all records
.Open "SELECT * FROM Postcode" & " WHERE [Postcode] = '" & target &
"'", cn, , , adCmdText
If Not rs.EOF Then
waarde = rs.Fields(intColIndex).Value
soortnummer = rs.Fields(intColIndex + 1).Value
Select Case soortnumer
Case 0
vannummer0 = rs.Fields(intColIndex + 2).Value
totnummer0 = rs.Fields(intColIndex + 3).Value
Case 1
vannummer1 = rs.Fields(intColIndex + 2).Value
totnummer1 = rs.Fields(intColIndex + 3).Value
End Select
straatnummer = rs.Fields(intColIndex + 4).Value
plaatsnummer = rs.Fields(intColIndex + 5).Value
Else
antwoord = MsgBox("Deze postcode bestaat niet!")
TargetRange.Select
Exit Sub
End If
'TargetRange.Offset(1, 0).CopyFromRecordset rs ' the recordset data
End With
rs.Close

How can i make de code loop?
once for case 0 and once for case 1

Greetings Hans


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default how do i loop in a access search

Hans,

If you want to access the second record use

rs.MoveNext

If you want to loop through many records use something like:

Do Until rs.EOF
'Do something
Rs.MoveNext
Loop

--

John Green - Excel MVP
Sydney
Australia


"hans" wrote in message ...
I can get my data out of access but i only find the first record.
Most of the time there ar two records in acces that i need to find.
I use the folloing code.

With rs
' open the recordset
'.Open TableName, cn, adOpenStatic, adLockOptimistic, adCmdTable
' all records
.Open "SELECT * FROM Postcode" & " WHERE [Postcode] = '" & target &
"'", cn, , , adCmdText
If Not rs.EOF Then
waarde = rs.Fields(intColIndex).Value
soortnummer = rs.Fields(intColIndex + 1).Value
Select Case soortnumer
Case 0
vannummer0 = rs.Fields(intColIndex + 2).Value
totnummer0 = rs.Fields(intColIndex + 3).Value
Case 1
vannummer1 = rs.Fields(intColIndex + 2).Value
totnummer1 = rs.Fields(intColIndex + 3).Value
End Select
straatnummer = rs.Fields(intColIndex + 4).Value
plaatsnummer = rs.Fields(intColIndex + 5).Value
Else
antwoord = MsgBox("Deze postcode bestaat niet!")
TargetRange.Select
Exit Sub
End If
'TargetRange.Offset(1, 0).CopyFromRecordset rs ' the recordset data
End With
rs.Close

How can i make de code loop?
once for case 0 and once for case 1

Greetings Hans




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default how do i loop in a access search

hans wrote:
I can get my data out of access but i only find the first record.
Most of the time there ar two records in acces that i need to find.
I use the folloing code.


You will need to use the MoveNext method of the recordset.

With rs
' open the recordset
'.Open TableName, cn, adOpenStatic, adLockOptimistic, adCmdTable
' all records
.Open "SELECT * FROM Postcode" & " WHERE [Postcode] = '" & target &
"'", cn, , , adCmdText
If Not rs.EOF Then

change the above line to:
Do While Not rs.EOF

waarde = rs.Fields(intColIndex).Value
soortnummer = rs.Fields(intColIndex + 1).Value
Select Case soortnumer
Case 0
vannummer0 = rs.Fields(intColIndex + 2).Value
totnummer0 = rs.Fields(intColIndex + 3).Value
Case 1
vannummer1 = rs.Fields(intColIndex + 2).Value
totnummer1 = rs.Fields(intColIndex + 3).Value
End Select
straatnummer = rs.Fields(intColIndex + 4).Value
plaatsnummer = rs.Fields(intColIndex + 5).Value
Else

change the Else to:
rs.MoveNext
Loop

antwoord = MsgBox("Deze postcode bestaat niet!")
TargetRange.Select
Exit Sub
End If

the above 4 lines would have to be moved elsewhere or you could add
this line of code:
If rs.BOF and rs.EOF then

This rs would only be at the beginning and ending of the file at the
same time if there are no records.

'TargetRange.Offset(1, 0).CopyFromRecordset rs ' the recordset data
End With
rs.Close

How can i make de code loop?
once for case 0 and once for case 1

Greetings Hans




Hope this helps,

Matthew

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default how do i loop in a access search

Thanks it works.

Greetings Hans
"Heiko" schreef in bericht
...
Hello Hans

With rs
.Open "SELECT * FROM Postcode" & " WHERE [Postcode] = '" &
target &
"'", cn, , , adCmdText
Do
If Not .EOF Then
waarde = .Fields(intColIndex).Value
soortnummer = .Fields(intColIndex + 1).Value
Select Case soortnumer
Case 0
vannummer0 = .Fields(intColIndex + 2).Value
totnummer0 = .Fields(intColIndex + 3).Value
Case 1
vannummer1 = .Fields(intColIndex + 2).Value
totnummer1 = .Fields(intColIndex + 3).Value
End Select
straatnummer = .Fields(intColIndex + 4).Value
plaatsnummer = .Fields(intColIndex + 5).Value
Else
antwoord = MsgBox("Deze postcode bestaat niet!")
.Close
TargetRange.Select
Exit Sub
End If
.MoveNext
Loop Until .EOF
.Close
End With

Heiko
:-)

"hans" wrote:

I can get my data out of access but i only find the first record.
Most of the time there ar two records in acces that i need to find.
I use the folloing code.

With rs
' open the recordset
'.Open TableName, cn, adOpenStatic, adLockOptimistic, adCmdTable
' all records
.Open "SELECT * FROM Postcode" & " WHERE [Postcode] = '" & target

&
"'", cn, , , adCmdText
If Not rs.EOF Then
waarde = rs.Fields(intColIndex).Value
soortnummer = rs.Fields(intColIndex + 1).Value
Select Case soortnumer
Case 0
vannummer0 = rs.Fields(intColIndex + 2).Value
totnummer0 = rs.Fields(intColIndex + 3).Value
Case 1
vannummer1 = rs.Fields(intColIndex + 2).Value
totnummer1 = rs.Fields(intColIndex + 3).Value
End Select
straatnummer = rs.Fields(intColIndex + 4).Value
plaatsnummer = rs.Fields(intColIndex + 5).Value
Else
antwoord = MsgBox("Deze postcode bestaat niet!")
TargetRange.Select
Exit Sub
End If
'TargetRange.Offset(1, 0).CopyFromRecordset rs ' the recordset

data
End With
rs.Close

How can i make de code loop?
once for case 0 and once for case 1

Greetings Hans





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
Do Loop or use End iF for search string RGreen Excel Discussion (Misc queries) 4 September 1st 09 12:59 AM
Find loop doesn't loop JSnow Excel Discussion (Misc queries) 2 June 24th 09 08:28 PM
Access Form In An Access Report (SubForm) Question Gary Links and Linking in Excel 0 January 27th 06 05:54 AM
How do I search excel spreadsheets using multiple search criteria. Kasper Excel Worksheet Functions 4 December 15th 05 12:26 AM
search & copy with loop Don Guillett[_4_] Excel Programming 0 July 24th 03 02:55 PM


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