Re: if loop with "<=" condition doesn't work with Records

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Graham,
I hope I didn't sound critical. I just meant to alert the poster that
he/she might need to alter the code a bit or alter the table. In other
words, the poster needed to make a change and needed to decide which way to
eliminate the possibility of ambiguous results.

Perhaps I should have gone into further detail and offered a specific
solution.

Thanks for your understanding,
John Spencer

"Graham R Seach" <gseach@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:e4%23sCiPAGHA.2908@xxxxxxxxxxxxxxxxxxxxxxx
> John,
>
> What you say is true, however, the poster's code (as is) merely gets the
> first row that matches the criteria, and as we know, the term "first" is
> rather arbitrary. He could have used DLookup, to similar effect. At least
> with a recordset, he has the opportunity to sort the result.
>
> Regards,
> Graham R Seach
> Microsoft Access MVP
> Sydney, Australia
>
>
> "John Spencer" <spencer@xxxxxxxxx> wrote in message
> news:OO$fqLMAGHA.2984@xxxxxxxxxxxxxxxxxxxxxxx
>> The poster would need to change his table if you are going to use
>> BETWEEN. For example 200 would match two rows in his table. Your code
>> would work, but it would return two rows in this case. Since the query
>> has no order by clause it is __possible__ that it could return different
>> values on subsequent runs. Not probable, but it is possible.
>>
>> "Graham R Seach" <gseach@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
>> news:eD7hdWKAGHA.980@xxxxxxxxxxxxxxxxxxxxxxx
>>> Riyaz,
>>>
>>> This is a better way:
>>> Dim rs As DAO.Recordset
>>> Dim sSQL As String
>>>
>>> sSQL = "SELECT price " & _
>>> "FROM myTable " & _
>>> "WHERE " & Txtlimit.Value & " BETWEEN [upper] AND
>>> [lower]"
>>>
>>> Set rstAISI4140NQT = DBEngine(0)(0).OpenRecordset(sSQL,
>>> dbOpenSnapshot)
>>> If rstAISI4140NQT.AbsolutePosition > -1 Then
>>> Txtpkg.Value = rstAISI4140NQT!price
>>> MsgBox (" price calculated ")
>>> Else
>>> MsgBox (" price not found ")
>>> End If
>>>
>>> rstAISI4140NQT.Close
>>> Set rstAISI4140NQT = Nothing
>>>
>>> Regards,
>>> Graham R Seach
>>> Microsoft Access MVP
>>> Sydney, Australia
>>> ---------------------------
>>>
>>> "riyaz" <riyaz@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>>> news:226F4266-BC6C-4B96-B4B7-04C937167DE8@xxxxxxxxxxxxxxxx
>>>> this is my table structure
>>>>
>>>> lower upper price
>>>>
>>>> 100 200 $7.20
>>>> 200 300 $8.10
>>>> 300 400 $10.90
>>>>
>>>> from here i want to extract the price depend the input limit value
>>>>
>>>> for eg:// if the limit value entered in textbox is 150 .it should
>>>> navigate the table
>>>> and give the correct price for this limit value $7.20
>>>>
>>>> my code is:
>>>>
>>>> Do Until rstAISI4140NQT.EOF
>>>>
>>>> If Txtlimit.Value <= rstAISI4140NQT("upper") And Txtlimit.Value
>>>> >=
>>>> rstAISI4140NQT("lower") Then
>>>>
>>>>
>>>> Txtpkg.Value = rstAISI4140NQT("price")
>>>>
>>>>
>>>> MsgBox (" price calculated ")
>>>>
>>>> Exit Do
>>>> Exit Sub
>>>>
>>>>
>>>> End If
>>>>
>>>> rstAISI4140NQT.MoveNext
>>>>
>>>>
>>>> Loop
>>>>
>>>> by this code i cannot get the price value..i found frm this code that
>>>> operator
>>>> it doesnot check the"<=" condition
>>>>
>>>> "<=" doesnot work in this looping..
>>>>
>>>> plz give me some solution
>>>> niyaz@xxxxxxxxxxxxxx
>>>
>>>
>>
>>
>
>


.



Relevant Pages

  • Re: Press "1" for English
    ... rather than be referred back to the installing company they receive ... replies from "industry members" with all kinds of advice. ... allows end users to alter their system regardless of whether or not ... Graham was no longer in Waco but was in Houston which made taking a job ...
    (alt.security.alarms)
  • Re: Press "1" for English
    ... I have never been able to get an end user to actually alter his or her own ... user codes without screwing something up. ... Graham was no longer in Waco but was in Houston which made taking a job ... I have no interest in expanding my coverage area. ...
    (alt.security.alarms)
  • Re: if loop with "<=" condition doesnt work with Records
    ... Graham R Seach ... Canberra, Australia ... the poster needed to make a change and needed to decide which way ... >> Microsoft Access MVP ...
    (microsoft.public.access.modulesdaovba)
  • Re: Access to Word - mergin with images
    ... New try to get picture into the poster: just a square with red cross ... > Graham Mayor - Word MVP ... >> I def have images in that folder, and each records image name is help ...
    (microsoft.public.word.mailmerge.fields)
  • GRAHAM!!! THE MINIMUM!!! ARE YOU THERE??? (Was: Re: Full course question)
    ... interpreted any remarks by the poster to be in any way abusive. ... All of these comments are from someone called 'The Magnum'. ... Time to own up, Graham! ...
    (uk.radio.amateur)