473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Form after_update not firing =[

374 256MB
Hi all,

I have a weird problem and likely just something in my code I am missing completely.

Basically I use similar code on sub form within a form and the after update event runs correctly.

However with the following code the after update will not fire. I have added a msgbox to see exactly and the msgbox does not load so clearly the event isn't.

This code resides in a subform subfrmcorrective on my main form:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Sub btncorrectivefirst_Click()
  5. On Error GoTo Err_btncorrectivefirst_Click
  6.  
  7.  
  8.     DoCmd.GoToRecord , , acFirst
  9.  
  10. Exit_btncorrectivefirst_Click:
  11.     Exit Sub
  12.  
  13. Err_btncorrectivefirst_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_btncorrectivefirst_Click
  16.  
  17. End Sub
  18. Private Sub btnpreviouscorrective_Click()
  19. On Error GoTo Err_btnpreviouscorrective_Click
  20.  
  21.  
  22.     DoCmd.GoToRecord , , acPrevious
  23.  
  24. Exit_btnpreviouscorrective_Click:
  25.     Exit Sub
  26.  
  27. Err_btnpreviouscorrective_Click:
  28.     MsgBox Err.Description
  29.     Resume Exit_btnpreviouscorrective_Click
  30.  
  31. End Sub
  32. Private Sub btngotolastcorrective_Click()
  33. On Error GoTo Err_btngotolastcorrective_Click
  34.  
  35.  
  36.     DoCmd.GoToRecord , , acLast
  37.  
  38. Exit_btngotolastcorrective_Click:
  39.     Exit Sub
  40.  
  41. Err_btngotolastcorrective_Click:
  42.     MsgBox Err.Description
  43.     Resume Exit_btngotolastcorrective_Click
  44.  
  45. End Sub
  46. Private Sub btnnextcorrective_Click()
  47. On Error GoTo Err_btnnextcorrective_Click
  48.  
  49.  
  50.     DoCmd.GoToRecord , , acNext
  51.  
  52. Exit_btnnextcorrective_Click:
  53.     Exit Sub
  54.  
  55. Err_btnnextcorrective_Click:
  56.     MsgBox Err.Description
  57.     Resume Exit_btnnextcorrective_Click
  58.  
  59. End Sub
  60. Private Sub btnaddactioncorrective_Click()
  61. On Error GoTo Err_btnaddactioncorrective_Click
  62.  
  63.  
  64.     DoCmd.GoToRecord , , acNewRec
  65.  
  66. Exit_btnaddactioncorrective_Click:
  67.     Exit Sub
  68.  
  69. Err_btnaddactioncorrective_Click:
  70.     MsgBox Err.Description
  71.     Resume Exit_btnaddactioncorrective_Click
  72.  
  73. End Sub
  74. Private Sub btndeleteacorrective_Click()
  75. On Error GoTo Err_btndeleteacorrective_Click
  76.  
  77.  
  78.     DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
  79.     DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
  80.  
  81. Exit_btndeleteacorrective_Click:
  82.     Exit Sub
  83.  
  84. Err_btndeleteacorrective_Click:
  85.     MsgBox Err.Description
  86.     Resume Exit_btndeleteacorrective_Click
  87.  
  88. End Sub
  89. Private Sub btnsavecorrective_Click()
  90. On Error Resume Next
  91.  
  92. 'DoCmd.RunCommand acCmdSaveRecord
  93. Me.Dirty = False
  94.  
  95.     Exit Sub
  96. End Sub
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. Private Sub Form_AfterUpdate()
  104. MsgBox "hi"
  105. End Sub
  106.  
  107. Private Sub Form_BeforeUpdate(Cancel As Integer)
  108.  
  109. Dim ErrorStrings As String
  110.  
  111. 'Create the error form validation stuff here
  112.  
  113. ErrorStrings = vbNullString
  114.  
  115. If MsgBox("Changes have been made to this record." _
  116.         & vbCrLf & vbCrLf & "Do you want to save these changes?" _
  117.         , vbYesNo, "Changes Made...") = vbYes Then
  118.  
  119.  
  120.  
  121.  
  122. If Len(Nz(Me.CorrectivePersonCarryout)) < 1 Then
  123.     Me.CorrectivePersonCarryout.SetFocus
  124.     Me.CorrectivePersonCarryout.BackColor = vbRed
  125.     Cancel = True
  126.     ErrorStrings = ErrorStrings & "You must enter the name of the person who will be carrying out the action." & vbCrLf
  127.  
  128. Else
  129.  
  130.     Me.CorrectivePersonCarryout.BackColor = 16579561
  131.  
  132. End If
  133.  
  134. If Len(Nz(Me.CorrectiveDate)) < 1 Then
  135.  
  136.  
  137.     Me.CorrectiveDate.SetFocus
  138.     Me.CorrectiveDate.BackColor = vbRed
  139.     Cancel = True
  140.     ErrorStrings = ErrorStrings & "You must enter a proposed date for the action to start." & vbCrLf
  141.  
  142. Else
  143.  
  144.     Me.CorrectiveDate.BackColor = 16579561
  145.  
  146. End If
  147.  
  148. If Len(Nz(Me.CorrectiveCompletedDate)) < 1 Or (Me.CorrectiveDate > Me.CorrectiveCompletedDate) Then
  149.  
  150.     Me.CorrectiveCompletedDate.SetFocus
  151.     Me.CorrectiveCompletedDate.BackColor = vbRed
  152.     Cancel = True
  153.     ErrorStrings = ErrorStrings & "You must enter a proposed date for the action to be completed. This must not be before the start date." & vbCrLf
  154. Else
  155.  
  156.     Me.CorrectiveCompletedDate.BackColor = 16579561
  157.  
  158. End If
  159.  
  160.  
  161. If Len(Nz(Me.CorrectiveDescription)) < 4 Then
  162.  
  163.     Me.CorrectiveDescription.SetFocus
  164.     Me.CorrectiveDescription.BackColor = vbRed
  165.     Cancel = True
  166.     ErrorStrings = ErrorStrings & "You must supply an adequate description for the action." & vbCrLf
  167.  
  168. Else
  169.  
  170.     Me.CorrectiveDescription.BackColor = 16579561
  171.  
  172. End If
  173.  
  174.  
  175. 'Create the if statement to see if anything has been done incorrectly before allowing continuation
  176.  
  177. If Len(Nz(ErrorStrings)) > 0 Then
  178.  
  179. 'error has occured cancel any save of the record
  180.  
  181.     MsgBox ErrorStrings, vbInformation, "Errors in your entries"
  182.  
  183. DoCmd.CancelEvent
  184. Exit Sub
  185. Else
  186. 'everything looks to be ok allow the code to continue running
  187. MsgBox "Action saved.", vbInformation, "Success"
  188.  
  189.  
  190. End If
  191.  
  192. Else
  193. DoCmd.RunCommand acCmdUndo
  194. Me.CorrectivePersonCarryout.BackColor = 16579561
  195. Me.CorrectiveDate.BackColor = 16579561
  196. Me.CorrectiveCompletedDate.BackColor = 16579561
  197. Me.CorrectiveDescription.BackColor = 16579561
  198.  
  199.     End If
  200. End Sub
  201.  
  202. Public Sub Form_Current()
  203. 'Start open ended error handler
  204. On Error GoTo tagError16
  205. 'Provide record counter for costs
  206. Dim rst3 As DAO.Recordset
  207. Dim lngCount3 As Long
  208.  
  209. Set rst3 = Me.RecordsetClone
  210.  
  211. With rst3
  212. If .RecordCount > 0 Then
  213. .MoveLast
  214. .MoveFirst
  215. End If
  216.  
  217. 'Show the results of the count
  218. If Me.CurrentRecord > .RecordCount Then
  219.  
  220. Me.txtCorrectiveRecNo = "New Corrective Record"
  221.  
  222. Else
  223.  
  224. Me.txtCorrectiveRecNo = "Corrective record " & Me.CurrentRecord & " of " & .RecordCount
  225.  
  226. End If
  227. End With
  228. 'End of successful code
  229. HadEnough:
  230. Set rst3 = Nothing
  231. Exit Sub
  232.  
  233. 'Handle the error type code
  234. tagError16:
  235.     MsgBox Err.Description
  236.     Resume HadEnough
  237.  
  238. End Sub
  239.  
  240.  
It does basic form validation after a save button is clicked and a user selects whether they want to save changes or not. I will be using the after update event to update my on change event code.

Thanks for any help,

Chris
Aug 15 '10 #1
11 2242
Stewart Ross
2,545 Expert Mod 2GB
Hi Chris. Can't tell much from what you've posted, but it appears likely that your Before_Update routine is causing the Update event to be cancelled.

Your tests in the Before_Update don't seem right to me; for example

Expand|Select|Wrap|Line Numbers
  1. If Len(Nz(Me.CorrectiveCompletedDate)) < 1 Or (Me.CorrectiveDate > Me.CorrectiveCompletedDate) Then
Not sure why you are testing for length of Nz when you can use IsNull to test for null directly. You should not be Or'ing the other clause which tests against another date field if null is a possibility.

There are also repeated tests of similar things in your Before_Update which suggest sub-optimal design.

As a start in debugging this set a breakpoint in your Before_Update sub and single step through each line to see which If is causing the Cancel to be set true.

-Stewart
Aug 15 '10 #2
munkee
374 256MB
The validation works correctly, even with the dates as I have set out I use the len just to see if anything has been entered in to the field. I have the cancel = true set for each validation incase only 1 occurs which could be any. I guess I could move the cancel = true to the later statement where I check the length of errorstring to see if any error messages have been added.

However I do not think this is where my issue is with the before update. If I step through my code ensuring there is no invalid entries in my form It runs through perfectly fine from the save button click even, through before_update and then exit subs back at the end of the on click save event. But there doesnt seem to be any after update involved.

Thank you for pointing out poor design, I am self taught so I find this is a given with most of what I do

Edit: Just saw ure edit, I think I ended up ditching IsNull through laziness when I found that len < 1 appeared to give me the same result (and I could keep copying the code block quickly to check lengths that were actually required to be above a set amount). However if this is incorrect as you suggest I think I should be changing it.

Edit2: Just realised I have no error proofing within my beforeupdate event so just to remind myself to get that added in tomorrow.
Aug 15 '10 #3
Stewart Ross
2,545 Expert Mod 2GB
Hi Chris. If Before_Update is firing but After_Update is not then something is happening in Before_Update which is cancelling the event - otherwise the After_Update event would definitely fire. You'll notice there is no Cancel parameter for After_Update - After_Update cannot be cancelled once it is raised.

If you are uncertain about this I'd suggest that you comment out the whole of your before_update event code and make a change to the data underlying your form; you are almost certain to see the message box you've placed in the After_Update appear unless there are other factors we don't know of in play!

-Stewart
Aug 16 '10 #4
munkee
374 256MB
Thanks for the advice Stewart. It seems we are in the "other factors" area as I have just removed my before update event code and the record saves without firing after_update.

I have stepped through the code and it never leaves my save button sub, it works through this correctly but nothing occurs either before or after the event click. I have a msgbox set up in the after update to see when it fires but still nothing.


Edit:

What I'm finding weird is the after update event is firing in all of my other forms. Also I dont know whether I am just tired but I'm pretty sure some of my validation on other forms that was working correctly seems to be not working correctly now and I have to dumb down the checks for them to work.

e.g. to check for a null or zls I was using something along the lines of:

Len(Nz(Me.controlname, "")) = 0

but I now have to check for the null and the zls seperately.


Edit 2:

ARGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH HHHHH!

I have just pasted my before update event code back in to my form and now the before update won't fire =| what the hell is going on!
Aug 16 '10 #5
munkee
374 256MB
OK I have decided im going to just rewrite the code for this page as I will spend more time trying to fix it than I can just writing it again and checking through.

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Option Compare Database
  3.  
  4.  
  5. Private Sub btnsavecorrective_Click()
  6. If Me.Dirty = True Then Me.Dirty = False
  7. Debug.Print "Dirty record fired"
  8. End Sub
  9.  
  10.  
  11. Private Sub Form_AfterUpdate()
  12. On Error GoTo HelpME
  13. DoCmd.GoToRecord , , acNext
  14. DoCmd.GoToRecord , , acPrevious
  15.  
  16. erm:
  17. Debug.Print "After Update Fired"
  18. Exit Sub
  19.  
  20. HelpME:
  21. MsgBox Err.Description
  22. Resume erm
  23. End Sub
  24.  
  25. Private Sub Form_BeforeUpdate(Cancel As Integer)
  26. Debug.Print "Before Update Fired"
  27. End Sub
Resultant in immediate window:
Expand|Select|Wrap|Line Numbers
  1. Before Update Fired
  2. After Update Fired
  3. Dirty record fired
So clearly things are working, I will just keep checking this as I go along. I may find the code which caused the error eventually.
Aug 16 '10 #6
NeoPa
32,556 Expert Mod 16PB
I would guess that, while the code is all available in your module, the properties which tell the form to use the code (BeforeUpdate & AfterUpdate) are not currently set on this form to "[Event Procedure]".
Aug 16 '10 #7
NeoPa
32,556 Expert Mod 16PB
Ah. Now you have it all linked up again (Your output indicates that), may I suggest that you replace your new vestigial code with the previous, more involved code, and test it again.
Aug 16 '10 #8
munkee
374 256MB
I will give that a go again after lunch Neo. Out of interest why doesn't access sync the [Event Procedure] within the form ? I would have expected it to do this just before a switch from design view or a check done during a vba compile etc.
Aug 16 '10 #9
NeoPa
32,556 Expert Mod 16PB
Munkee:
Out of interest why doesn't access sync the [Event Procedure] within the form ? I would have expected it to do this just before a switch from design view or a check done during a vba compile etc.
It's not qualified as a mind-reader :p

You decide which processes should be triggered (if any) upon firing of any event. You may have your own reasons for wanting a coincidentally named procedure in your module. Maybe as a test alternative. I'm testing the handling of the event with a procedure, and separately with a macro. I don't want to lose my procedure when I set it to test the macro, yet I don't want it to override my choice by setting it to the procedure either.

When you set the property Access will automatically create a stub of the procedure if one doesn't already exist. Doing the reverse is not something it can safely do without making un-supported assumptions.
Aug 16 '10 #10
munkee
374 256MB
After rewriting the code everything seems to be firing correctly. Not a clue what was going wrong I cant see any difference..
Aug 16 '10 #11
NeoPa
32,556 Expert Mod 16PB
I'm confused.

Do you have reason to believe it wasn't due to the event properties not being set to point to the associated code? I thought we'd resolved that bit.
Aug 16 '10 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on...
3
by: Matthew | last post by:
I am trying to build a form that has certain criteria on it (combo boxes) which a user can pick from a range of values to specify the criteria he wants when he runs a query on the form. I am...
2
by: Bart Lateur | last post by:
I'd like to have validation of the inputted text, in a form textbox. I want to give the user the option to try again, or to cancel out after which the textbox is either cleared or restored. I just...
9
by: Sandy | last post by:
Hi all, I have a form to list records (frmListIssue) which I call from different other forms. My wish is to display a message when the form is called and empty; no records to display. I want to...
2
by: Nenad Dobrilovic | last post by:
Hi, is there any way to find out how form was closed (by calling it's method Close() or by clicking on the 'close' button in control box)? Also, can I close the form in that way that Cloing/Closed...
3
by: dbuchanan | last post by:
It's easy to disable the Minimizebox and Maximizebox because they are members of the form, but how do I disable the Closebox or whatever it is called??? (Why are some things so hard to find...
0
by: hazz | last post by:
I would like to have control over datagridview events so that when a user 'single clicks' anywhere on the grid, a method call is made to a service and if a user 'double clicks' a Customer detail...
3
by: gazelle04 | last post by:
Which happens first AfterUpdate event of a form or Clicked event of a button on a form. I have these codes on an AfterUpdate of a form: If UpdateDone = True Then ...
4
by: Lysander | last post by:
Using Access 2003 Last night I created a new form, nothing special or funny about it. It has 3 toggle buttons on it, and I put an after_update event on them but it failed to work. I now find...
2
by: maxx429 | last post by:
Hi all, I am a VBA newb. I know probably just enough to be dangerous. :) Anyway, I have a Form that I am using <a href="http://allenbrowne.com/AppAuditCode.html">Allen Brown's Audit Trail</a> ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.