Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Location
    MidWest
    Posts
    6

    Unanswered: Type Mismatch error when pulling previous record value.

    I have searched for recordset information and pulled code from various posts. I am trying to pull my form's previuos record of [Balance] and transfer that to the corrent recordsets field of [CalcField].
    With the code I have found I get a type mismatch error.
    Here is the code I have...

    The Debit, Deposit, Balance, and CalcField are all Currency. Can anyone point me to the problem. I have tried specifying DAO.Recordset, but everytime I do, my computer locks and I have to End Task. I have sent the error reports to MS, They told me to update to SP3 so I did. My computer still locks if I use DAO.Recordset. So, I just left it as Recordset.

    Private Sub Balance_GotFocus()
    On Error GoTo Err_Balance_GotFocus

    Dim rs As Recordset
    Set rs = Me.RecordsetClone
    rs.Bookmark = Me.Bookmark

    'Move to the previous record
    rs.MovePrevious
    If Not rs.BOF Then
    Test = Test + rs.Fields(strFieldName)
    End If

    Me.CalcField = Test

    If IsEmpty(Me.Deposit) Then
    Me.Balance = Me.CalcField - Me.Debit
    Else
    Me.Balance = Me.CalcField + Me.Deposit
    End If

    Exit_Balance_GotFocus:
    Exit Sub

    Err_Balance_GotFocus:
    MsgBox Err.Description
    Resume Exit_Balance_GotFocus

    End Sub

    TIA

    Ben AKA Elevtro

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    when you are referring to a field in a recordset you need the "!" operator as in:
    variable = recordset!fieldName

    also, your strFieldName appears to be undefined

    izy

  3. #3
    Join Date
    Sep 2003
    Location
    MidWest
    Posts
    6
    Originally posted by izyrider
    when you are referring to a field in a recordset you need the "!" operator as in:
    variable = recordset!fieldName

    also, your strFieldName appears to be undefined

    izy
    I made these changes. Is this correct? If so, I am still gettign a type mismatch error.

    Dim Test As Currency
    ......
    Test = Test + rs!Balance
    ....
    rs.MoveNext

    rs!CalcField = Test

    If IsEmpty(rs!Deposit) Then
    rs!Balance = rs!CalcField - rs!Debit
    Else
    rs!Balance = rs!CalcField + rs!Deposit
    End If

    Is that what you mean when you say to refer to a field in a recorset with the ! operator? If you can't tell I am totaly new at this.

  4. #4
    Join Date
    Sep 2003
    Location
    MidWest
    Posts
    6
    Originally posted by izyrider
    when you are referring to a field in a recordset you need the "!" operator as in:
    variable = recordset!fieldName

    also, your strFieldName appears to be undefined

    izy
    Ok, I recreated this at work on Access 2002 instead of Access 2000 and the problem lies with in the
    Dim rs As Recordset Needs to be
    Dim rs As DAO.Recordset to work properly. Do you know of any issues with Access 2000 not using the DAO library correctly? I have 2 computers at home that I have tried this with and both of them lock up when I add any refference to DAO.

    Thank you.

Posting Permissions

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