Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Get Max Value from String? 1

Status
Not open for further replies.

spongie1

Technical User
Nov 24, 2003
57
0
0
US
I am putting a recordset values into a string, but I am having a little trouble storing the highest value into a variable. The type of rs1.Fields(0).Value is Variant/Double.

I thought I could do something like:

Dim Highval

if highval < rs1.Fields(0).Value then
highval = rs1.Fields(0).Value
end if (... putting this portion inside the loop)

However, I am having trouble picking the right variable type... (is it double?)

I am also having trouble intializing the variable... (do I need to somehow allocate space for this variable?)

I am having trouble performing the comparision... (once I get the first two problems fixed.. the if statement should work right?)


Code:
  Dim rs1 As Recordset
  Dim frm As Access.Form
  Dim values1 As String 

  Set rs1 = frm.Recordset

  If rs1.RecordCount > 0 Then
  rs1.MoveFirst
    trendlineCtr = 0
    Do While Not rs1.EOF
        values1 = values1 & (rs1.Fields(0).Value) & Chr(9)
        
        rs1.MoveNext
        trendlineCtr = trendlineCtr + 1
    Loop
  rs1.Close
  Set rs1 = Nothing
[\code]
 
You might try
[tt]
Dim rs1 As Recordset
Dim frm As Access.Form
Dim values1 As String
Dim Highval As Double
' Can be either Variant or Double

Set rs1 = frm.Recordset

If NOT (rs1.EOF AND rs1.BOF) Then
rs1.MoveFirst
highval = rs1.Fields(0).Value
trendlineCtr = 0
Do While Not rs1.EOF
values1 = values1 & (rs1.Fields(0).Value) & Chr(9)
If highval < rs1.Fields(0).Value then highval = rs1.Fields(0).Value

rs1.MoveNext
trendlineCtr = trendlineCtr + 1
Loop
rs1.Close
Set rs1 = Nothing
[/tt]
 
Thanks Golem, I gave you a star.

I had everything but the

highval = rs1.Fields(0).Value after the rs1.MoveFirst

Most appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top