Problem with SetFocus

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim Devenish

    #1

    Problem with SetFocus

    In my application vehicles arrive and depart from a workshop. The
    ArrivalDate and the HandoverDate are each entered. Sometimes the
    person who should enter the arrival date forgets to do so.

    When the vehicle is handed over to the customer and the HandoverDate is
    entered I wish to warn about the possibly missing ArrivalDate. In the
    BeforeUpdate event of HandoverDate I have:

    Private Sub HandoverDate_Be foreUpdate(Canc el As Integer)
    If Not IsNull(Me.Hando verDate) And IsNull(Me.Arriv alDate) Then
    MsgBox "Please enter the Arrival date and then re-enter the
    Handover date", ,
    "This vehicle appears not to have arrived"
    Cancel = True
    Me.HandoverDate .Undo
    Me.ArrivalDate. SetFocus
    End If
    End Sub

    Everything works fine except for the final SetFocus. This gives rise
    the error:
    Run-time error 2108: You must save the field before you execute the
    SetFocus method.
    That is clear enough but I am undoing the entry and cancelling the
    update. I guess that the Cancel does not have an effect until the
    event routine has exited.

    Where do I sensibly put the SetFocus?

    I could put it in the AfterUpdate event but I would then have to put
    some boolean variable in the BeforeUpdate and test it in AfterUpdate.
    Seems a bit too messy.

  • fredg

    #2
    Re: Problem with SetFocus

    On 7 Aug 2006 03:26:27 -0700, Jim Devenish wrote:
    In my application vehicles arrive and depart from a workshop. The
    ArrivalDate and the HandoverDate are each entered. Sometimes the
    person who should enter the arrival date forgets to do so.
    >
    When the vehicle is handed over to the customer and the HandoverDate is
    entered I wish to warn about the possibly missing ArrivalDate. In the
    BeforeUpdate event of HandoverDate I have:
    >
    Private Sub HandoverDate_Be foreUpdate(Canc el As Integer)
    If Not IsNull(Me.Hando verDate) And IsNull(Me.Arriv alDate) Then
    MsgBox "Please enter the Arrival date and then re-enter the
    Handover date", ,
    "This vehicle appears not to have arrived"
    Cancel = True
    Me.HandoverDate .Undo
    Me.ArrivalDate. SetFocus
    End If
    End Sub
    >
    Everything works fine except for the final SetFocus. This gives rise
    the error:
    Run-time error 2108: You must save the field before you execute the
    SetFocus method.
    That is clear enough but I am undoing the entry and cancelling the
    update. I guess that the Cancel does not have an effect until the
    event routine has exited.
    >
    Where do I sensibly put the SetFocus?
    >
    I could put it in the AfterUpdate event but I would then have to put
    some boolean variable in the BeforeUpdate and test it in AfterUpdate.
    Seems a bit too messy.
    What Boolean test?

    Why cancel the valid Handover entry and then re-enter it just because
    a different entry has not been yet made?
    Save the Handover entry THEN set focus to the missing Arrival field.

    In the Handover AfterUpdate event:

    If Not IsNull(Me.Hando verDate) And IsNull(Me.Arriv alDate) Then
    MsgBox "This vehicle appears not to have arrived." _
    & vbNewLine & "Please enter the Arrival date."
    Me.ArrivalDate. SetFocus
    End If
    --
    Fred
    Please respond only to this newsgroup.
    I do not reply to personal e-mail

    Comment

    • Jim Devenish

      #3
      Re: Problem with SetFocus

      The possible problem with this is - if the user then forgets or ignores
      to enter the required arrival date before closing the form, the record
      is saved without an arrival date. To overcome this I would have to
      make the test when closing the form. Maybe, on balance, that could be a
      better place to do the test, preventing the closure of the form if no
      arrival date has been entered.

      I am wanting to ensure that it is not possible to have a handover date
      but no arrival date.


      fredg wrote:
      >
      What Boolean test?
      >
      Why cancel the valid Handover entry and then re-enter it just because
      a different entry has not been yet made?
      Save the Handover entry THEN set focus to the missing Arrival field.
      >
      In the Handover AfterUpdate event:
      >
      If Not IsNull(Me.Hando verDate) And IsNull(Me.Arriv alDate) Then
      MsgBox "This vehicle appears not to have arrived." _
      & vbNewLine & "Please enter the Arrival date."
      Me.ArrivalDate. SetFocus
      End If
      --
      Fred
      Please respond only to this newsgroup.
      I do not reply to personal e-mail

      Comment

      • fredg

        #4
        Re: Problem with SetFocus

        On 7 Aug 2006 07:13:36 -0700, Jim Devenish wrote:
        The possible problem with this is - if the user then forgets or ignores
        to enter the required arrival date before closing the form, the record
        is saved without an arrival date. To overcome this I would have to
        make the test when closing the form. Maybe, on balance, that could be a
        better place to do the test, preventing the closure of the form if no
        arrival date has been entered.
        >
        I am wanting to ensure that it is not possible to have a handover date
        but no arrival date.
        >
        fredg wrote:
        >
        >>
        >What Boolean test?
        >>
        >Why cancel the valid Handover entry and then re-enter it just because
        >a different entry has not been yet made?
        >Save the Handover entry THEN set focus to the missing Arrival field.
        >>
        >In the Handover AfterUpdate event:
        >>
        >If Not IsNull(Me.Hando verDate) And IsNull(Me.Arriv alDate) Then
        > MsgBox "This vehicle appears not to have arrived." _
        > & vbNewLine & "Please enter the Arrival date."
        > Me.ArrivalDate. SetFocus
        > End If
        >--
        >Fred
        >Please respond only to this newsgroup.
        >I do not reply to personal e-mail
        Re: >preventing the closure of the form if no arrival date has been
        entered. <
        Forms can display many records.
        Don't you mean 'prevent saving the record you are on', rather than
        just closing the form.

        Place the code in the Form's BeforeUpdate event to prevent leaving the
        record without entering the Arrival date if the Handover date has been
        entered.

        If Not IsNull(Me.Hando verDate) And IsNull(Me.Arriv alDate) Then
        MsgBox "This vehicle appears not to have arrived." _
        & vbNewLine & "Please enter the Arrival date."
        Me.ArrivalDate. SetFocus
        End If

        Then also place the following code in the Form's BeforeUnload event:

        If Not IsNull(Me.Hando verDate) And IsNull(Me.Arriv alDate) Then
        MsgBox "This vehicle appears not to have arrived." _
        & vbNewLine & "Please enter the Arrival date."
        Cancel = True
        Me.ArrivalDate. SetFocus
        End If

        Now you won't be able to close the form without entering the Arrival
        date if the Handover date has been entered in the record currently
        displayed.
        --
        Fred
        Please respond only to this newsgroup.
        I do not reply to personal e-mail

        Comment

        Working...