Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Oct 2002
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VB code flows randomly (2000)

    I'm trying to modify some VB code that's in the 'On Lost Focus' event for a field. The code that I am providing here has been reduced in complexity for illustration, but still reproduces the problem. For instance, I have explicitly assigned values to the PNIEndValue and PNIStartValue variables, rather than involving outside code to do so.

    When this code is invoked, it starts off by bouncing back and forth between PNIEndValue = "ICA" and PNIStartValue = "PNI-Official Check" -- although I can see it flash very very briefly on If PNIEndValue <> PNIStartValue while it's doing this. After doing this about 30 times, it finally does travel down line by line, all the way to End Sub, but then loops part of the way way up and repeats this for a couple of dozen times.

    The funny thing is that all of this is transparent to the users. It works from the form as originally designed. I just noticed it acting this way because I need to make some modifications, but can't until I can get it stabalized.

    I have compacted, repaired, decompiled, deleted other events (for now) ... what else should I try to debug this?

    Any suggestions are welcome.

    Best regards -

    Howard

    ================================================== =======
    Private Sub txtComboTypeOfItem_LostFocus()
    Dim PNIEndValue As String
    Dim PNIStartValue As String

    PNIEndValue = "ICA"
    PNIStartValue = "PNI-Official Check"

    If PNIEndValue <> PNIStartValue Then
    If (Not IsNull(Me![txtCheckSerialNbr]) Or PNIEndValue = "PNI") And Me![txtComboTypeOfItem] <> "PNI-AMEX TC" Then
    Me![PNIInfo].Visible = True
    Me![txtBkgCtrContactName].SetFocus
    Me![Welcome].Visible = False
    End If

    If (Not IsNull(Me![txtCheckSerialNbr]) Or PNIEndValue = "PNI") And Me![txtComboTypeOfItem] = "PNI-AMEX TC" Then
    MsgBox "adding new code here."
    End If
    End If

    End Sub

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: VB code flows randomly (2000)

    Unfortunately, I think we need more information to determine exactly what is going on with you code. It appears to me to be behaving more or less as I would expect, but there may be other code involved that is setting focus back to the control with retriggers the code with loss of focus, so you appear to have an endless loop.

    In particular, it would be useful to know if this is some sort of validation routine for a control. Also, it would be useful to know what the various referenced controls are supposed to represent. In particular these controls appear to be key:
    Me![PNIInfo
    Me![txtBkgCtrContactName
    Me![Welcome]

    Have you tried stepping through it with the de###### to see if it appears to be behaving correctly? I suspect there is some other code getting in on the act.
    Wendell

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: VB code flows randomly (2000)

    Coud you perhaps move it to the controls AfterUpdate event and see what happens?
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

Posting Permissions

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