Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Delta, Br. Columbia
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Access VB run time error (Access 2000)

    I have a form and 2 subforms that have a fair amount of code behind them that perform calculations on the data when the user tabs along between fields. This normally works fine. However when the user exits the form having changed the content of a field , tabbed to the next field or clicked the exit button, the onlost focus event that normally works absolutely fine generates a runtime error as follows:

    (VB) Run-time error '-2147352567 (80020009)'

    The data has been changed

    This is probably a stupid question but what dose this error mean.

    The options given are End and Debug. Clicking End does not appear to harm the data but ??. Clicking Debug shows the OnLostFocus event of the field that is loosing the focus ar the calculation module. (code shown below):

    !This is the LostFocus code that is apparently crashing. The code is on the sub form

    Private Sub PL_Cut1_Our_2Gal_LostFocus()
    If IsNull([PL_Cut1_Our_2Gal]) Then
    [PL_Cut1_Our_2Gal] = 0
    End If
    PL_Cut1_toTake = Cut1toTake([PL_LEFT], ([PL_Cut1_Future] + [PL_Cut1_Our_2Gal] + [PL_Cut1_Our_1Gal]), ([PL_Cut2_Orders] + [PL_Cut3_Orders]), Forms![frmCut1_Planning_Master]![Cutpercent])
    W_Recalc
    End Sub

    ! This if the public function that is called

    Option Compare Database
    Option Explicit
    Dim n


    Public Function Cut1toTake(InvLeft, TotFuture, TotOrders, Cut1)

    If (InvLeft - TotFuture) < 0 And Cut1 <> 0 Then
    If InvLeft > 0 Then
    Cut1toTake = Abs((InvLeft - TotFuture) / Cut1)
    Else
    If (InvLeft * -1 - TotOrders) < 0 Then
    Cut1toTake = TotFuture
    Else
    Cut1toTake = (Abs(InvLeft) + TotFuture) / Cut1
    End If
    End If
    Else
    Cut1toTake = 0
    End If


    End Function

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Access VB run time error (Access 2000)

    That does not look like an Access run time error.
    What command does it in fact stop on (yellow highlighting will tell you)?
    Have you compiled the code?

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Access VB run time error (Access 2000)

    What is W_Recalc? It's just hanging out there in its own line, but if it's a function, you'll need to tell us what it does. I don't see anything else in the LostFocus event that should cause you problems.
    Charlotte

  4. #4
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Delta, Br. Columbia
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Access VB run time error (Access 2000)

    Sorry about that. Here is the W_Recalc procedure. It and the LostFocus event are part of the sub-form code, while Cut1toTake is a general module. In stepping through the code the error occurs at the end of the Cut1toTake procedure that is executed from the onlost focus event. I have to confess that the biggest problem is understanding this rather cryptic error msg. The stmnt seems a bit obvious (i.e. the data has changed so what?).

    Public Sub W_Recalc()

    On Error GoTo Err_W_Recalc

    Me.Recalc
    If Forms![frmCut1_Planning_Master].Tot_toTake > Forms![frmCut1_Planning_Master].Sum_Available Then
    Forms![frmCut1_Planning_Master].Tot_toTake.BackColor = RGB(255, 0, 0)
    Forms![frmCut1_Planning_Master].Tot_toTake.ForeColor = RGB(255, 255, 0)
    Forms![frmCut1_Planning_Master].Tot_toTake.FontBold = True
    Forms![frmCut1_Planning_Master].Tot_toTake.Enabled = False
    Forms![frmCut1_Planning_Master].Tot_toTake.Locked = True
    Else
    Forms![frmCut1_Planning_Master].Tot_toTake.BackColor = RGB(255, 255, 255)
    Forms![frmCut1_Planning_Master].Tot_toTake.ForeColor = RGB(0, 0, 0)
    Forms![frmCut1_Planning_Master].Tot_toTake.FontBold = False
    Forms![frmCut1_Planning_Master].Tot_toTake.Enabled = False
    Forms![frmCut1_Planning_Master].Tot_toTake.Locked = True
    End If

    Exit_W_Recalc:

    Exit Sub

    Err_W_Recalc:
    Dim Newline As String, msg As String
    Newline = Chr$(13) & Chr$(10)
    Select Case Err
    Case 3022 ' duplicate value in key
    msg = "You have entered a duplicate Size"
    msg = msg & Newline
    msg = msg & "Enter a different Size"
    MsgBox msg
    Me![PL_Cut_Size].SetFocus
    Resume Exit_W_Recalc
    Case 3058 ' null value
    msg = "You must enter a valid size"
    MsgBox msg
    Me![PL_Cut_Size].SetFocus
    Resume Exit_W_Recalc
    Case Else
    msg = Str$(Err) + " " + Error$
    MsgBox msg
    Resume Exit_W_Recalc
    End Select

    End Sub

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Access VB run time error (Access 2000)

    So what is frmCut1_Planning_Master? Is that the parent form or the subform? And do you get the same error if you move the code to the AfterUpdate event instead of LostFocus? There isn't much point in recalculating controls unless a value has been changed and a conflict of events can occur when you click a button directly from a control you've just changed. The AfterUpdate event is more reliable in that situation than LostFocus.
    Charlotte

  6. #6
    2 Star Lounger
    Join Date
    Jan 2002
    Location
    Delta, Br. Columbia
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Access VB run time error (Access 2000)

    Thank you for your response. First to answer your question, frmCut1_Planning_Master is the main form and possibly using the afterupdate event would solve the problem. The problem as you correctly point out is a conflict of events. The "data has changed" message referred to the fact that the incoming parameters for the module had changed during execution.

    It all points to the fact that I need to really learn a lot more about object oriented programming (having been a linear programmer for far too many years).

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Access VB run time error (Access 2000)

    Actually, what you need to learn about is event-driven programming as opposed to linear/procedural programming. That's the hardest paradigm shift for many programmers. I took a VB class once, and one of the students had a terrible time understanding that the code in a module didn't start with the declarations at the top and execute to the bottom, going through all the routines in between! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Charlotte

Posting Permissions

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