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: - Option Compare Database
-
Option Explicit
-
-
Private Sub btncorrectivefirst_Click()
-
On Error GoTo Err_btncorrectivefirst_Click
-
-
-
DoCmd.GoToRecord , , acFirst
-
-
Exit_btncorrectivefirst_Click:
-
Exit Sub
-
-
Err_btncorrectivefirst_Click:
-
MsgBox Err.Description
-
Resume Exit_btncorrectivefirst_Click
-
-
End Sub
-
Private Sub btnpreviouscorrective_Click()
-
On Error GoTo Err_btnpreviouscorrective_Click
-
-
-
DoCmd.GoToRecord , , acPrevious
-
-
Exit_btnpreviouscorrective_Click:
-
Exit Sub
-
-
Err_btnpreviouscorrective_Click:
-
MsgBox Err.Description
-
Resume Exit_btnpreviouscorrective_Click
-
-
End Sub
-
Private Sub btngotolastcorrective_Click()
-
On Error GoTo Err_btngotolastcorrective_Click
-
-
-
DoCmd.GoToRecord , , acLast
-
-
Exit_btngotolastcorrective_Click:
-
Exit Sub
-
-
Err_btngotolastcorrective_Click:
-
MsgBox Err.Description
-
Resume Exit_btngotolastcorrective_Click
-
-
End Sub
-
Private Sub btnnextcorrective_Click()
-
On Error GoTo Err_btnnextcorrective_Click
-
-
-
DoCmd.GoToRecord , , acNext
-
-
Exit_btnnextcorrective_Click:
-
Exit Sub
-
-
Err_btnnextcorrective_Click:
-
MsgBox Err.Description
-
Resume Exit_btnnextcorrective_Click
-
-
End Sub
-
Private Sub btnaddactioncorrective_Click()
-
On Error GoTo Err_btnaddactioncorrective_Click
-
-
-
DoCmd.GoToRecord , , acNewRec
-
-
Exit_btnaddactioncorrective_Click:
-
Exit Sub
-
-
Err_btnaddactioncorrective_Click:
-
MsgBox Err.Description
-
Resume Exit_btnaddactioncorrective_Click
-
-
End Sub
-
Private Sub btndeleteacorrective_Click()
-
On Error GoTo Err_btndeleteacorrective_Click
-
-
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
-
-
Exit_btndeleteacorrective_Click:
-
Exit Sub
-
-
Err_btndeleteacorrective_Click:
-
MsgBox Err.Description
-
Resume Exit_btndeleteacorrective_Click
-
-
End Sub
-
Private Sub btnsavecorrective_Click()
-
On Error Resume Next
-
-
'DoCmd.RunCommand acCmdSaveRecord
-
Me.Dirty = False
-
-
Exit Sub
-
End Sub
-
-
-
-
-
-
-
Private Sub Form_AfterUpdate()
-
MsgBox "hi"
-
End Sub
-
-
Private Sub Form_BeforeUpdate(Cancel As Integer)
-
-
Dim ErrorStrings As String
-
-
'Create the error form validation stuff here
-
-
ErrorStrings = vbNullString
-
-
If MsgBox("Changes have been made to this record." _
-
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
-
, vbYesNo, "Changes Made...") = vbYes Then
-
-
-
-
-
If Len(Nz(Me.CorrectivePersonCarryout)) < 1 Then
-
Me.CorrectivePersonCarryout.SetFocus
-
Me.CorrectivePersonCarryout.BackColor = vbRed
-
Cancel = True
-
ErrorStrings = ErrorStrings & "You must enter the name of the person who will be carrying out the action." & vbCrLf
-
-
Else
-
-
Me.CorrectivePersonCarryout.BackColor = 16579561
-
-
End If
-
-
If Len(Nz(Me.CorrectiveDate)) < 1 Then
-
-
-
Me.CorrectiveDate.SetFocus
-
Me.CorrectiveDate.BackColor = vbRed
-
Cancel = True
-
ErrorStrings = ErrorStrings & "You must enter a proposed date for the action to start." & vbCrLf
-
-
Else
-
-
Me.CorrectiveDate.BackColor = 16579561
-
-
End If
-
-
If Len(Nz(Me.CorrectiveCompletedDate)) < 1 Or (Me.CorrectiveDate > Me.CorrectiveCompletedDate) Then
-
-
Me.CorrectiveCompletedDate.SetFocus
-
Me.CorrectiveCompletedDate.BackColor = vbRed
-
Cancel = True
-
ErrorStrings = ErrorStrings & "You must enter a proposed date for the action to be completed. This must not be before the start date." & vbCrLf
-
Else
-
-
Me.CorrectiveCompletedDate.BackColor = 16579561
-
-
End If
-
-
-
If Len(Nz(Me.CorrectiveDescription)) < 4 Then
-
-
Me.CorrectiveDescription.SetFocus
-
Me.CorrectiveDescription.BackColor = vbRed
-
Cancel = True
-
ErrorStrings = ErrorStrings & "You must supply an adequate description for the action." & vbCrLf
-
-
Else
-
-
Me.CorrectiveDescription.BackColor = 16579561
-
-
End If
-
-
-
'Create the if statement to see if anything has been done incorrectly before allowing continuation
-
-
If Len(Nz(ErrorStrings)) > 0 Then
-
-
'error has occured cancel any save of the record
-
-
MsgBox ErrorStrings, vbInformation, "Errors in your entries"
-
-
DoCmd.CancelEvent
-
Exit Sub
-
Else
-
'everything looks to be ok allow the code to continue running
-
MsgBox "Action saved.", vbInformation, "Success"
-
-
-
End If
-
-
Else
-
DoCmd.RunCommand acCmdUndo
-
Me.CorrectivePersonCarryout.BackColor = 16579561
-
Me.CorrectiveDate.BackColor = 16579561
-
Me.CorrectiveCompletedDate.BackColor = 16579561
-
Me.CorrectiveDescription.BackColor = 16579561
-
-
End If
-
End Sub
-
-
Public Sub Form_Current()
-
'Start open ended error handler
-
On Error GoTo tagError16
-
'Provide record counter for costs
-
Dim rst3 As DAO.Recordset
-
Dim lngCount3 As Long
-
-
Set rst3 = Me.RecordsetClone
-
-
With rst3
-
If .RecordCount > 0 Then
-
.MoveLast
-
.MoveFirst
-
End If
-
-
'Show the results of the count
-
If Me.CurrentRecord > .RecordCount Then
-
-
Me.txtCorrectiveRecNo = "New Corrective Record"
-
-
Else
-
-
Me.txtCorrectiveRecNo = "Corrective record " & Me.CurrentRecord & " of " & .RecordCount
-
-
End If
-
End With
-
'End of successful code
-
HadEnough:
-
Set rst3 = Nothing
-
Exit Sub
-
-
'Handle the error type code
-
tagError16:
-
MsgBox Err.Description
-
Resume HadEnough
-
-
End Sub
-
-
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
11 2242
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 - 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
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.
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
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!
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. - Option Explicit
-
Option Compare Database
-
-
-
Private Sub btnsavecorrective_Click()
-
If Me.Dirty = True Then Me.Dirty = False
-
Debug.Print "Dirty record fired"
-
End Sub
-
-
-
Private Sub Form_AfterUpdate()
-
On Error GoTo HelpME
-
DoCmd.GoToRecord , , acNext
-
DoCmd.GoToRecord , , acPrevious
-
-
erm:
-
Debug.Print "After Update Fired"
-
Exit Sub
-
-
HelpME:
-
MsgBox Err.Description
-
Resume erm
-
End Sub
-
-
Private Sub Form_BeforeUpdate(Cancel As Integer)
-
Debug.Print "Before Update Fired"
-
End Sub
Resultant in immediate window: - Before Update Fired
-
After Update Fired
-
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.
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]".
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.
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.
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.
After rewriting the code everything seems to be firing correctly. Not a clue what was going wrong I cant see any difference..
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
...
|
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...
|
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> ...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
| |