Results 1 to 4 of 4
  1. #1
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262

    Beforeupdate to early

    Hi



    I have a form to add records to a table.

    On the form I have several controls I wish to force to be edited (they are calculated and stored depending on user input) before the user can move onto the next record.

    I had command buttons which 99% of users have user and had no issues until someone discovered the Ctrl+ shortcut to insert new record.

    Since this passes the checks I embedded into the command buttons it allows then to bypass the psuedo validation.

    I initially looked at disabling the shortcut, however I found a post from Allen Browne Suggesting against this and using the form update property.

    My issue is simple yet annoying

    The before update fires after the first control is edited, i wish to try to stop it until the user attempt to goto a new record.

    Enclosed below is my vb.

    Text47 is a calculated field, it checks to see whether 3 concatenated fields already and prevent that 'work order' being duplicated.

    Hopefully someone can save my little grey cells

    Code:
     
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If [Text47] = "Error" Then
    MsgBox "The work order you are trying to create already exists please change the snow, sheet or line, or cancel creating a new work order", vbOKOnly, "Work order already exists"
    GoTo exit_sub:
    End If
    If IsNull([SNOW]) Or IsNull([Sheet]) Or IsNull([Line]) Or IsNull(Task) Or IsNull([Planned pulse]) Or IsNull([Task Type]) Or ([Sheet] <> 0 And [Predicted AC Hrs] = 0 And [Predicted AV Hrs] = 0) Then
    MsgBox "You must input data into all fields marked with a red label", vbOKOnly, "Not All required data entered"
    GoTo exit_sub:
    End If
    exit_sub:
    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That seems odd because the before update event should not fire until the user tries to leave the record. It is commonly used to validate data:

    http://www.baldyweb.com/BeforeUpdate.htm

    Are you sure there isn't some code that is forcing a save of the record?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    R_Badger is offline Knows a few tricks
    Windows XP Access 2003
    Join Date
    Feb 2012
    Location
    Suffolk, UK
    Posts
    262
    Thanks!

    I had forgotten about a me.recalc hidden on the control I was looking at!

    I also added a cancel=true line into the beforeupdate!

    Thanks Again.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. exit form using BeforeUpdate 'or' cmdButton
    By ConfusedMike in forum Forms
    Replies: 9
    Last Post: 09-21-2011, 10:05 PM
  2. BeforeUpdate in a Form in Datasheet view
    By fitshase in forum Forms
    Replies: 7
    Last Post: 07-29-2011, 08:53 AM
  3. Call .dll Code On BeforeUpdate?
    By phi11yguy19 in forum Programming
    Replies: 0
    Last Post: 07-02-2011, 10:20 PM
  4. Validation BeforeUpdate Errors
    By huv123 in forum Programming
    Replies: 3
    Last Post: 02-07-2011, 10:25 AM
  5. BeforeUpdate and AfterUpdate Question
    By gsurfdude in forum Programming
    Replies: 0
    Last Post: 04-03-2008, 07:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums