Re: if loop with "<=" condition doesn't work with Records
- From: "John Spencer" <spencer@xxxxxxxxx>
- Date: Thu, 15 Dec 2005 08:33:07 -0500
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
>>>
>>>
>>
>>
>
>
.
- Follow-Ups:
- Re: if loop with "<=" condition doesn't work with Records
- From: Graham R Seach
- Re: if loop with "<=" condition doesn't work with Records
- References:
- if loop with "<=" condition doesn't work with Records
- From: riyaz
- Re: if loop with "<=" condition doesn't work with Records
- From: Graham R Seach
- Re: if loop with "<=" condition doesn't work with Records
- From: John Spencer
- Re: if loop with "<=" condition doesn't work with Records
- From: Graham R Seach
- if loop with "<=" condition doesn't work with Records
- Prev by Date: Re: UK postcodes in MS Access
- Next by Date: Re: Reset a number back to 1 at the beginning of the year
- Previous by thread: Re: if loop with "<=" condition doesn't work with Records
- Next by thread: Re: if loop with "<=" condition doesn't work with Records
- Index(es):
Relevant Pages
|