locked
Choosing No on a msgbox to go back to the field RRS feed

  • Question

  •   I have a continuous form.  When the user enters a value > 0.039, I want to display a message.  If they select NO, then I want to go back to the field for entry.  Yet, the code goes to the next field instead of going to back to the field I just setfocus on.  Is this because it is a continuous form and I am display several records from the table and Access gets confused?  I do not get any errors, it just places the cursor on the next field.  Here is the code and can someone plz help me to understand this?  I have read some examples and played with this and I do not get it.  Thanx in advance.

    Private Sub SIR_Rate_36_AfterUpdate()

    If SIR_Rate_36 > 0.039 Then
        Rate_36_Error = MsgBox("Above Standard Rate, Is this Correct?", 4)
        If Rate_36_Error = 7 Then
            Cancel = False
            SIR_Rate_36.SetFocus
            GoTo errkey1
        End If
    End If

    errkey1:

    End Sub

    Saturday, March 30, 2019 2:47 PM

Answers

  • Simply remove the line

            Me.SIR_Rate_36.SetFocus

    By setting Cancel = True, the SIR_Rate_36 control will remain the active control, so you don't need SetFocus.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by ballj_351 Saturday, March 30, 2019 6:08 PM
    Saturday, March 30, 2019 3:36 PM

All replies

  • I just changed the code to try this and now I am getting an error dialog box and it is on the setfocus line:

    Private Sub SIR_Rate_36_BeforeUpdate(Cancel As Integer)

    If SIR_Rate_36 > 0.039 Then
        Rate_36_Error = MsgBox("Above Standard Rate, Is this Correct?", 4)
        If Rate_36_Error = 7 Then
            Cancel = True
            Me.Undo
            Me.SIR_Rate_36.SetFocus
            GoTo errkey2
        End If
    End If

    errkey2:

    End Sub

    Saturday, March 30, 2019 3:14 PM
  • Simply remove the line

            Me.SIR_Rate_36.SetFocus

    By setting Cancel = True, the SIR_Rate_36 control will remain the active control, so you don't need SetFocus.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by ballj_351 Saturday, March 30, 2019 6:08 PM
    Saturday, March 30, 2019 3:36 PM
  • You are exactly correct.  Thank you very much!
    Saturday, March 30, 2019 6:09 PM