473,472 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

AfterUpdate code does not seem to run in all cases

10 New Member
I have a form that keeps track of keys given to employees. We decided to add a feature to keep a digital signature for the keys so I created a second table to hold the signature and enough information to tie the signature to the key(s) issued. When the information is added to the form, the user clicks on a command button to save and exit the form;

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command71_Click()
  2.     On Error GoTo Command71_Error
  3.     If Not IsNumeric(Me!DOOR) Then
  4.       MsgBox "You must enter a numeric value for 'Door'"
  5.       Me!ROOM.SetFocus
  6.       Me!DOOR.SetFocus
  7.     Else
  8.        strGEmpNum = ""
  9.        DoCmd.Close acForm, "KEYSADD", acSaveYes
  10.     End If
  11.  
  12.    Exit Sub
  13.  
  14. Command71_Error:
  15.     MsgBox Err.Description
  16.  
  17. End Sub

I added code in the AfterUpdate exit point to add a record to the signature file as a holder record for signature. I am finding that holder record is not always created/saved.

I added code to catch an error on the write, but the users say they have not seen the error produced. In as much as you can not always trust the users, I am entering this forum topic to see if there is a flaw in my processing. I don't see why the process works 95% of the time, yet in some cases the AfterUpdate code does not seem to fire. A common scenerio is that the user will enter a record, hit save, immediately go back into the form to enter a new key, repeat. Could this cause an issue?

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterUpdate()
  2.  
  3. On Error GoTo InsertErr
  4.  
  5. Dim EN As String
  6. Dim KN As String
  7. Dim CD As String
  8. Dim ID As String
  9. Dim FN As String
  10. Dim DP As String
  11. Dim LN As String
  12. Dim BD As String
  13. Dim RM As String
  14. Dim bSecondkey As Boolean
  15. Dim iCounter As Integer
  16. Dim lPause As Long
  17.  
  18. iCounter = 0
  19.  
  20.  
  21. Dim stLinkCriteria As String
  22. Dim strRunSQL As String
  23.  
  24. EN = Me.EMPLOYEEIDnew.Value
  25. KN = Me.KEYNUM.Value
  26. CD = Me.CODE.Value
  27. ID = Me.ISSUEDATE
  28. ID2 = Me.ISSUEDATE2
  29. FN = Me.FIRSTNAME
  30. DP = Me.DEPARTMENT
  31. LN = Me.LASTNAME
  32. BD = Me.BUILDING
  33. RM = Me.ROOM
  34.  
  35. bSecondkey = False
  36.  
  37. If Len(ID2) > 0 Then
  38.    bSecondkey = True
  39. End If
  40.  
  41. retry_write:
  42.  
  43. strRunSQL = "INSERT INTO [ISSUEDKEYS-ACCESS] (EMPLOYEENUMBER, KEYNUM, ISSUEDATE, LASTNAME, FIRSTNAME, DEPARTMENT, CODE, BUILDING, ROOM, REISSUEDKEY, SECONDCOPY )" & _
  44.  " VALUES (" & "'" & EN & "', '" & KN & "', '" & ID & "', '" & LN & "', '" & FN & "', '" & DP & "', '" & CD & "', '" & BD & "', '" & RM & "', " & False & ", " & bSecondkey & ")"
  45.  
  46. DoCmd.RunSQL strRunSQL
  47.  
  48. Exit_ER:
  49. Exit Sub
  50.  
  51.  
  52. InsertErr:
  53. ' on error code added 8/8/07
  54. ' the following code is to do a retry of  the insert if there is an error
  55. If iCounter < 1 Then
  56.    iCounter = iCounter + 1
  57.    lPause = 5
  58.    Pause (lPause)
  59.    Resume retry_write:
  60. End If
  61.  
  62. ' the following code generates an error message if the insert fails
  63. MsgBox Err.Description & Err.Number
  64. Resume Exit_ER
  65.  
  66.  
  67. End Sub
Aug 20 '07 #1
7 1709
MGrowneyARSI
90 New Member
They may be overwriting the old record you could try locking down the form on open and on click of save and on exit create a sub that locks all the fields or me.Field_Name.locked call it LockAll or something likewise and call it on open on close and on click of save then create a sub that does the exact opposite you will want to create an add new record button and call the unlock on click of this one. This way you are forcing the user to only be able to create a new record it will also keep them from being able to edit records they have entered in the past last of all take away the record navigation buttons and set the cycle property to current record on the form. This may or may not help but it sounds like that may be what is going on.
Aug 20 '07 #2
pltmcs
10 New Member
Thank you for your response and suggestions. I understood part of what you wanted, but a big problem is that I need to keep it simple for the users and changing the process, even just adding a button or two, will get major push back.

I checked and the cycle property is set to current, but my record locks property is set to "No Locks". Should I change it?

As for adding the locking code. Can I change the Close (save) to two DoCmds and do the lock before the save and unlock after the save but before the close? The particular form is set to not allow edits, only adds, so I don't have to guard against updates.
Aug 21 '07 #3
MGrowneyARSI
90 New Member
Are you seting your fields = variables and then saving the variables to the table I seen this done before it's a real pain and could be why your haveing issues
Aug 23 '07 #4
JKing
1,206 Recognized Expert Top Contributor
Are you seting your fields = variables and then saving the variables to the table I seen this done before it's a real pain and could be why your haveing issues
It definitely looks that way. The after update event occurs after the values on the form have been committed to the database. In this event you are doing a programmatic insert of the same data.
Aug 23 '07 #5
pltmcs
10 New Member
It definitely looks that way. The after update event occurs after the values on the form have been committed to the database. In this event you are doing a programmatic insert of the same data.
Okay, since the update sometimes works and sometimes does not, does that mean there is a timing issue where I was just getting lucky that the form still contained the data for the AfterUpdate code to use to insert into the other table?

As an attempted fix, I move the code out of the AfterUpdate and after the save of the form, but before the close. This seems to have it's own set of problems where I am getting a "Save Action is Canceled" message when the form save is being done. Should I open a new topic for this issue?
Aug 28 '07 #6
MGrowneyARSI
90 New Member
Where was your code in the first place after update of what? was it after update of a required field and why did you not just build the form strait from a query instead of setting this and saving that I say keep it simple stop with the setting variables and just build from a query I had to rebuild an entire database I was modifying because it was all written like this code above.
Aug 28 '07 #7
JKing
1,206 Recognized Expert Top Contributor
Hi, I think I've misinterpretted your problem. I originally thought you were inserting the same data from the form into the exact same table creating duplicate entries. I see now you have an additional table that you are keeping a copy of the data in.

Have you thought about using an append query to transfer the data over?
Aug 30 '07 #8

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

Similar topics

9
by: bigoxygen | last post by:
Hi. I'm using a 3 tier FrontController Design for my web application right now. The problem is that I'm finding to have to duplicate a lot of code for similar functions; for example, listing...
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
1
by: Chris Thompson | last post by:
I am using Access 97 (if this makes any difference to any answers). On a form I have a combobox and I want it such that when a user selects an item from the list, this executes an 'INSERT INTO'...
2
by: jv | last post by:
Hello, I have a Service Cancellation form that contain a CancelDate text box. The text box has an AfterUpdate event that perform a few calculations. This works fine. However, next to the text...
171
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles)...
1
imrosie
by: imrosie | last post by:
Please help with this one,,,,,I've been trying everything in my arsenal to fix this one. I'm stumped.... I"ve got a unbound combo box (customername) that has two events (on click); AfterUpdate and...
4
by: bcallnan | last post by:
Hello All- I am trying to reference a subform's afterupdate event that is 3 deep and am having some trouble getting it to work. The control is a combo box and i cannot seem to trigger the...
19
by: William Gill | last post by:
I seem to be having a mentally bad period lately . My code is beginning to be terrible convoluted mess, and I shudder to think what it will be like to go back in a couple months and try to follow...
12
by: Gerhard | last post by:
This is bizarre... Im having problems with the combobox AfterUpdate event: Im running Access 2003. I created an unbound combobox with 3 columns on a form. The Row Source is from a table....
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.