Results 1 to 1 of 1

Thread: Help needed

  1. #1
    Join Date
    Apr 2004
    Location
    Bucharest, Romania
    Posts
    16

    Question Unanswered: Help needed

    Hi,

    I'm looking for a better code. My problem:
    I have a query sort asc by id and date

    ID / TRANS / DATE
    Z1 / 2500 / 01.07.06
    Z1 / -300 / 02.07.06
    Z1 / -450 / 03.07.06
    Z1 / 225 / 03.07.06
    Z2 / 325 / 01.07.06
    Z2 / -226 / 01.07.06
    Z2 / -100 / 02.07.06
    ........................

    I need for each ID and DATE a value based on previous day value of TRANS + presend day value of TRANS

    ID / STK / DATE
    Z1 / 2500 / 01.07.06
    Z1 / 2200 / 02.07.06
    Z1 / 1975 / 03.07.06
    Z2 / 99 / 01.07.06
    Z2 / 0 / 02.07.06

    I figured out a code that seems to work fine at my computer but not to a different computer (Overflow?).

    Function d()
    DoCmd.SetWarnings False
    Dim stc As Integer
    Dim cod As String
    Dim codl As String
    Set db = CurrentDb
    Set rs = db.OpenRecordset("q4")
    codl = rs.Fields("ID")
    rs.MoveFirst
    stc = rs.Fields("TRANS")

    Do Until rs.EOF
    DATA = rs.Fields("DATE")
    codl = rs.Fields("cod")
    stc = rs.Fields("TRANS")
    If codl = cod Then
    If (strResult + stc) > 0 Then
    strResult = strResult + stc
    Else
    strResult = 0
    End If

    Else
    strResult = stc

    End If
    cod = codl
    Dim csql As String
    csql = "INSERT INTO restable VALUES ('" & codl & "', '" & strResult & "', '" & DATA & "')"
    DoCmd.RunSQL (csql)
    rs.MoveNext
    Loop

    End Function

    Appreciate if you can help me improve my code to work on any computer.

    Thanks,
    DNY
    Last edited by dny; 07-14-06 at 17:04.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •