|
|
|
date: Wed, 2 Jul 2008 19:15:31 -0700 (PDT),
group: microsoft.public.access.modulescoding
back
Re: looping parsing problem
On Jul 2, 10:15 pm, richal...@cs.com wrote:
> Can someone tell me best way of correcting the following code, in
> which I would like to move through the rows of a six-row dynaset,
> and on each line of the dynaset look for particular field values.
> If such a value is found, then the entire process can be exited.
> I've written the following, but it's not progressing thru the dynaset
> rows.
>
> Set MyDB = CurrentDb()
> Set MyData = MyDB.OpenRecordset("TopN", dbOpenDynaset)
> For l = 0 To MyDB.Recordsets.Count - 1
>
> Set TempRecordset = MyDB.Recordsets(l)
>
> For k = 11 To 14 'Fields of interest in each row
>
> v = TempRecordset.Fields(k).Value
> If v = "22" Then 'satisfactory result for exiting
> process
>
> End If
>
> Next k
>
> Next l
> TempRecordset.close
>
> Thanks
> Richard
Tom;
No, its not that I'm not exiting the loop if I find "22" in the first
row of dynaset. I already have a GOTO line in the code (that I didn't
bother including in my text).
The problem is that this code, as written, is not progressing thru the
dynaset to look for value = 22 in fields in the second, third, etc.
rows of the dynaset if the value is not found in first row.
I'm not sure where the error is, but "l" never goes past "0"----------
ie.--Recordsets.Count =1 (instead of TopN, which is really Top6.
date: Thu, 3 Jul 2008 05:32:27 -0700 (PDT)
author: unknown
Re: looping parsing problem
Hi Richard,
I think your problem lies with your "treatment" of the recordset. You can't
treat it as an array, and refer to records within it via a Recordset(n)
construct. You have to step through the recordset using the .MoveNext
method.
Something like the following (late-night air-code):
Dim MyDB as DAO.Database
Dim MyData as DAO.Recordset
Set MyDB = CurrentDb()
Set MyData = MyDB.OpenRecordset("TopN", dbOpenDynaset)
Do Until MyData.EOF
For k = 11 To 14 'Fields of interest in each row
v = MyData.Fields(k).Value
If v = "22" Then 'satisfactory result for exiting
'process
End If
Next k
MyData.MoveNext
Loop
MyData.close
Set MyData = Nothing
Your process code should also close the recordset and set it to Nothing if
it is exiting the routine via an ExitSub statement (although it probably
won't crash if you don't; but it's good practice to not leave things open if
they should be closed).
HTH,
Rob
wrote in message
news:348ce667-814b-4d6a-9f4c-5c2b3bf289cb@d1g2000hsg.googlegroups.com...
On Jul 2, 10:15 pm, richal...@cs.com wrote:
> Can someone tell me best way of correcting the following code, in
> which I would like to move through the rows of a six-row dynaset,
> and on each line of the dynaset look for particular field values.
> If such a value is found, then the entire process can be exited.
> I've written the following, but it's not progressing thru the dynaset
> rows.
>
> Set MyDB = CurrentDb()
> Set MyData = MyDB.OpenRecordset("TopN", dbOpenDynaset)
> For l = 0 To MyDB.Recordsets.Count - 1
>
> Set TempRecordset = MyDB.Recordsets(l)
>
> For k = 11 To 14 'Fields of interest in each row
>
> v = TempRecordset.Fields(k).Value
> If v = "22" Then 'satisfactory result for exiting
> process
>
> End If
>
> Next k
>
> Next l
> TempRecordset.close
>
> Thanks
> Richard
Tom;
No, its not that I'm not exiting the loop if I find "22" in the first
row of dynaset. I already have a GOTO line in the code (that I didn't
bother including in my text).
The problem is that this code, as written, is not progressing thru the
dynaset to look for value = 22 in fields in the second, third, etc.
rows of the dynaset if the value is not found in first row.
I'm not sure where the error is, but "l" never goes past "0"----------
ie.--Recordsets.Count =1 (instead of TopN, which is really Top6.
date: Thu, 3 Jul 2008 23:29:26 +1000
author: Rob Parker VETHIS
Re: looping parsing problem
On Thu, 3 Jul 2008 05:32:27 -0700 (PDT), richaluft@cs.com wrote:
Ah, I didn't even see that in first instance. You're missing
TempRecordset.MoveNext above the "Next I" line.
Also curious is why you're going over all recordsets in MyDB. Much
more typical is to go over MyData, it being the only recordset you
want to work with.
-Tom.
>On Jul 2, 10:15 pm, richal...@cs.com wrote:
>> Can someone tell me best way of correcting the following code, in
>> which I would like to move through the rows of a six-row dynaset,
>> and on each line of the dynaset look for particular field values.
>> If such a value is found, then the entire process can be exited.
>> I've written the following, but it's not progressing thru the dynaset
>> rows.
>>
>> Set MyDB = CurrentDb()
>> Set MyData = MyDB.OpenRecordset("TopN", dbOpenDynaset)
>> For l = 0 To MyDB.Recordsets.Count - 1
>>
>> Set TempRecordset = MyDB.Recordsets(l)
>>
>> For k = 11 To 14 'Fields of interest in each row
>>
>> v = TempRecordset.Fields(k).Value
>> If v = "22" Then 'satisfactory result for exiting
>> process
>>
>> End If
>>
>> Next k
>>
>> Next l
>> TempRecordset.close
>>
>> Thanks
>> Richard
>
>Tom;
>No, its not that I'm not exiting the loop if I find "22" in the first
>row of dynaset. I already have a GOTO line in the code (that I didn't
>bother including in my text).
>The problem is that this code, as written, is not progressing thru the
>dynaset to look for value = 22 in fields in the second, third, etc.
>rows of the dynaset if the value is not found in first row.
>I'm not sure where the error is, but "l" never goes past "0"----------
>ie.--Recordsets.Count =1 (instead of TopN, which is really Top6.
date: Thu, 03 Jul 2008 06:42:45 -0700
author: Tom van Stiphout
Re: looping parsing problem
On Jul 3, 9:29 am, "Rob Parker"
<NOSPAMrobppar...@optusnet.com.au.REMOVETHIS> wrote:
> Hi Richard,
>
> I think your problem lies with your "treatment" of the recordset. You can't
> treat it as an array, and refer to records within it via a Recordset(n)
> construct. You have to step through the recordset using the .MoveNext
> method.
>
> Something like the following (late-night air-code):
>
> Dim MyDB as DAO.Database
> Dim MyData as DAO.Recordset
>
> Set MyDB = CurrentDb()
> Set MyData = MyDB.OpenRecordset("TopN", dbOpenDynaset)
> Do Until MyData.EOF
> For k = 11 To 14 'Fields of interest in each row
> v = MyData.Fields(k).Value
> If v = "22" Then 'satisfactory result for exiting
> 'process
> End If
> Next k
> MyData.MoveNext
> Loop
> MyData.close
> Set MyData = Nothing
>
> Your process code should also close the recordset and set it to Nothing if
> it is exiting the routine via an ExitSub statement (although it probably
> won't crash if you don't; but it's good practice to not leave things open if
> they should be closed).
>
> HTH,
>
> Rob
>
> wrote in message
>
> news:348ce667-814b-4d6a-9f4c-5c2b3bf289cb@d1g2000hsg.googlegroups.com...
> On Jul 2, 10:15 pm, richal...@cs.com wrote:
>
>
>
>
>
> > Can someone tell me best way of correcting the following code, in
> > which I would like to move through the rows of a six-row dynaset,
> > and on each line of the dynaset look for particular field values.
> > If such a value is found, then the entire process can be exited.
> > I've written the following, but it's not progressing thru the dynaset
> > rows.
>
> > Set MyDB = CurrentDb()
> > Set MyData = MyDB.OpenRecordset("TopN", dbOpenDynaset)
> > For l = 0 To MyDB.Recordsets.Count - 1
>
> > Set TempRecordset = MyDB.Recordsets(l)
>
> > For k = 11 To 14 'Fields of interest in each row
>
> > v = TempRecordset.Fields(k).Value
> > If v = "22" Then 'satisfactory result for exiting
> > process
>
> > End If
>
> > Next k
>
> > Next l
> > TempRecordset.close
>
> > Thanks
> > Richard
>
> Tom;
> No, its not that I'm not exiting the loop if I find "22" in the first
> row of dynaset. I already have a GOTO line in the code (that I didn't
> bother including in my text).
> The problem is that this code, as written, is not progressing thru the
> dynaset to look for value = 22 in fields in the second, third, etc.
> rows of the dynaset if the value is not found in first row.
> I'm not sure where the error is, but "l" never goes past "0"----------
> ie.--Recordsets.Count =1 (instead of TopN, which is really Top6.- Hide quoted text -
>
> - Show quoted text -
Tom
Yes, this effects the correct action. Actually, I left out closing
data in my online code text
Thanks again
R
date: Thu, 3 Jul 2008 09:12:43 -0700 (PDT)
author: unknown
Re: looping parsing problem
On Jul 3, 8:32 am, richal...@cs.com wrote:
> On Jul 2, 10:15 pm, richal...@cs.com wrote:
>
>
>
>
>
> > Can someone tell me best way of correcting the following code, in
> > which I would like to move through the rows of a six-row dynaset,
> > and on each line of the dynaset look for particular field values.
> > If such a value is found, then the entire process can be exited.
> > I've written the following, but it's not progressing thru the dynaset
> > rows.
>
> > Set MyDB = CurrentDb()
> > Set MyData = MyDB.OpenRecordset("TopN", dbOpenDynaset)
> > For l = 0 To MyDB.Recordsets.Count - 1
>
> > Set TempRecordset = MyDB.Recordsets(l)
>
> > For k = 11 To 14 'Fields of interest in each row
>
> > v = TempRecordset.Fields(k).Value
> > If v = "22" Then 'satisfactory result for exiting
> > process
>
> > End If
>
> > Next k
>
> > Next l
> > TempRecordset.close
>
> > Thanks
> > Richard
>
> Tom;
> No, its not that I'm not exiting the loop if I find "22" in the first
> row of dynaset. I already have a GOTO line in the code (that I didn't
> bother including in my text).
> The problem is that this code, as written, is not progressing thru the
> dynaset to look for value = 22 in fields in the second, third, etc.
> rows of the dynaset if the value is not found in first row.
> I'm not sure where the error is, but "l" never goes past "0"----------
> ie.--Recordsets.Count =1 (instead of TopN, which is really Top6.- Hide quoted text -
>
> - Show quoted text -
No, this doesn't help, but rob parker's solution sees the light.
Thanks,
R
date: Thu, 3 Jul 2008 09:14:20 -0700 (PDT)
author: unknown
|
|