MsgBox not showing when it should

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tmdrake
    New Member
    • Mar 2013
    • 43

    MsgBox not showing when it should

    I have a form where the is an unbound textbox in header of the form where the user will enter how many weld are scanned before a pull test is performed. Next to it are two text boxes counting the scans, example: 1 of 5.
    Once the interval of 5 is reached a msgbox appears telling the user to perform a test. Now the problem is the msgbox does not appear until the sixth record is scanned. I sure hope this makes sense,not sure how to fix this problem. Below is the code I am using:

    Code:
    Private Sub Form_AfterInsert()
    If Not IsNull(Me.SN.Value) Then
        LastPosSN = Me.SN.Value
    End If
    If PosPullTestCount = Me.PullTestNum.Value Then
        MsgBox "Time to perform a pull-test on a scrap cell!"
        PosPullTestCount = 1
        Me.Text30.Value = Me.PullTestNum.Value
        DoCmd.OpenForm "GeneralTabPullTest"
    Else
        PosPullTestCount = PosPullTestCount + 1
        Me.Text30.Value = Me.PullTestNum.Value
    End If
    End Sub
    Thanks
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Please start here:
    >> Before Posting (VBA or SQL) Code.

    What you'll find, is that your code is adding the final count; however, you don't test value again until the next click event.

    Comment

    • tmdrake
      New Member
      • Mar 2013
      • 43

      #3
      Thanks, so how do I fix the code to tell it to test value on final count?

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        tmdrake:
        I don't mean to sound offish/condescending etc... really I don't; however, you really should be able to look at your code and be able to fix that issue - it is that fundamental.

        However:
        Put a "Stop" command just before line 2 in your posted code.
        Now start the event, the vba editor will start, you should arrange the windows so that you can get at the form and the vba editor, [F8] to step thru the code.
        Click and Step thru the code until you get to that 5th time... take note of your logic branch -
        When did you increment the value?
        When did you test it?

        Seriously, this will like the "I-could've-had-a-V8" commercials where the actor hits their head kind of momement.

        Goto the insights list: Microsoft Access / VBA Insights Sitemap
        Read thru articles: 136,135,133,132 ,131,130,129,12 8,127,126

        Comment

        Working...