Ask Experts Questions for FREE Help !
Ask
    rosy's Avatar
    rosy Posts: 2, Reputation: 1
    New Member
     
    #1

    Aug 23, 2006, 01:22 PM
    need help in VB Code
    Good day,

    Iam traying to get result of my record as below

    If next record is biger than previous show "1"
    If next record is same previous show "1"
    If next record is smallest show "0"
    if next record is same previous show "0"

    Example

    Code:
    id	Time		Code	Price	Res
       1	10:00:00 AM	1010	905     0
     464	10:00:34 AM	1010	906     1
     626	10:00:56 AM	1010	906	1
    1523	10:02:16 AM	1010	904	0
    1568	10:02:21 AM	1010	904	0
    1569	10:02:21 AM	1010	905	1
    the code gave me correct result for some filed and other incorrect !

    Could you please check the code and correct it for me.

    I have attached the DB for any correction

    Note: the command bottons on Form1 of Forms Object.

    the vb code:


    Private Sub cmdUpdate_Click()
    Dim cnn As ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim SQL As String
    Dim Code As String
    Dim Price As Long
    'Dim Res As String
    Dim Res As Variant
    'Dim PrevRes As String
    Dim PrevRes As Variant

    Set cnn = CurrentProject.Connection
    SQL = "Select [Code],[Price],[Res] from [tt]" & _
    " order by [Code],[ID]"

    rst.Open SQL, cnn, adOpenKeyset, adLockOptimistic

    Do While Not rst.EOF
    Code = rst![Code]
    Price = rst![Price]
    'PrevRes = ""
    PrevRes = Null
    rst.MoveNext
    Do While rst![Code] = Code
    'Res = IIf(rst![Price] > [Price], "1", IIf(rst![Price] < [Price], "0", IIf(rst![Price] = [Price], PrevRes, Null)))
    Res = IIf(rst![Price] > [Price], "1", IIf(rst![Price] < [Price], "0", PrevRes))
    rst![Res] = Res
    PrevRes = Res
    Price = rst![Price]
    rst.MoveNext
    If rst.EOF Then
    Exit Do
    End If
    Loop
    Loop
    Set cnn = Nothing
    Set rst = Nothing

    MsgBox "Res field updated."

    End Sub

    thanks for assistant . :)

    ..
    Attached Files
  1. File Type: zip VBA Access 2000.zip (15.0 KB, 29 views)
  2. rosy's Avatar
    rosy Posts: 2, Reputation: 1
    New Member
     
    #2

    Aug 24, 2006, 09:11 AM
    Iam sorry my expamle was not cleared.

    Asum that I have this fields: Id,Code,Price,Res

    the "res" field will show the vb code result

    if the current price = 905 then I input a new entery with price 905 the Res filed should show "0" because the price same as previous price. Then when I input a new entry with price 906 the result should show "1" because the previos record is less.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Code 19 with my Optical drives! [ 14 Answers ]

I was cleaning out my hard drive and streamlining my startup files and when I was done neither of my optical drives worked (CDRW and DVD+RW - both Buslink). Neither of them show up in "My Computer" and both have yellow !'s next to them in the device manager. At first when I clicked on them in the...

DaVinci Code [ 57 Answers ]

WARNING, if anyone has not read the book and wants to or plans on seeing the movie instead, I suggest they not read this thread. Discussion of the themes of the book may reveal plot twists and spoil enjoyment of the book. I just finished reading the book and found it very interesting. It's a...

Davinci Code [ 61 Answers ]

Just looking for thoughts and comments on the movie and book Davinci Code

Decode code [ 1 Answers ]

I am very happy to know about you. Please I am a Cameroonian and having a cingular phone with the following details. What happen with the phone is that my small brother took it and not knowing the operatings,entered a code that he could no longer remember.It show that he had changed the...


View more questions Search