Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a Before Update event to test the contents of a date field in a sub-form. If the date has been set to before today's date I want to output a message and end up with the cursor back the offending field.
    The code is ;

    Code:
    Private Sub EffectiveDate_BeforeUpdate(Cancel As Integer)
        If Me.EffectiveDate < Date Then
            MsgBox ("Setting Effective Date to earlier than today is not allowed." & Chr(13) & _
            "Please input a date equal to or greater than today's date.")
            Cancel = True
            Me.EffectiveDate.SetFocus
        End If
    End Sub
    When I do the test, I get the following error.

    Code:
    Run-time error '2108':
    
    You must save the field before you execute the GoToControl action, the GoToControl Method or the SetFocus method.
    I don't understand what this means apart from the fact that it isn't working!

    In desperation, I changed it to an AfterUpdate event and reset the date using OldValue, but still the SetFocus does not work; the cursor is left where the user put it e.g. by tabbling out of the field.

    What am I doing wrong, please?
    Thanks
    Silverback
    Silverback

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You don't need the line

    Me.EffectiveDate.SetFocus

    The line

    Cancel = True

    is sufficient: it will cancel the update and keep the focus in the EffectiveDate control.

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hans
    Thanks - that leaves the cursor in the offending field OK, but how can the old value be reinstated? I tried setting the field to OldValue and got another error :

    Runtime error 80020009
    The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing <DB Name> from saving data in the field.
    The offending line where it fails is Me.EffectiveDate = Me.EffectiveDate.OldValue

    (It doesn't matter whether this is put before or after the Cancel = True line.)
    Thanks
    Silverback
    Silverback

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Try

    Me.EffectiveDate.Undo

    to reset the value.

  5. #5
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Warrington, Cheshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by HansV View Post
    Try

    Me.EffectiveDate.Undo

    to reset the value.
    Perfect.
    Many thanks
    Silverback
    Silverback

Posting Permissions

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