Trying To Undo A Part Of A Sub Procedure
Sep 2, 2005
I am using unbound forms and multiple recordsets to save data into a number of tables. The save procedure is two parts: the first one saves data from a temporary table tblT to tblA. Second part takes the primary key of this new record in tblA and stores it with additional data in tblB.
In case there is an error, this procedure creates all kinds of problems. Usually the errors happen in the second part of the code and by then the data has already been saved in the tblA. On Error, the sub exits. When the user makes changes in the info and retries to save, the sub again tries to save data from the tblT to tblA, but now runs into primary key problems as the data already exists! (the reason for this is because the primary key field for tblA is filled with an autonumber generated by tblT).
Ideally, on error, the sub should delete the last record (or two or three, as the case may be) from tblA so that they can be re-stored by the sub on resumption. I cannot get either an SQL statement or a recordset to identify exactly these records to delete them. All help is highly appreciated! Also, any suggestions towards alternative methods of achieving this are most welcome!
Thanks in advance!
View Replies
ADVERTISEMENT
Jul 31, 2014
I have just made a change to one of the forms by adding a button (by copying the only other button on the form) to cancel any changes and close the form. However, as soon as I added it I started getting the error message in the title. Please attachment LA Err1 for the full message. I also changed the caption on the other button on the form from "Close Form" to "Save && Close Form" this button is now giving the same error.
I have Compacted and repaired the DB on several occasions to no avail. I have deleted the procedures from the module and recreated them using the properties window - still get the error. I have deleted the buttons from the form and recreated the both via the object wizard and without it. Nothing I have tried has made any effect.
View 5 Replies
View Related
May 4, 2006
I have a Memo box where the user puts comments and then I have a check box that if check automatically puts a specific phrase on the first line of the Memo box (before any other text currently in the box). What I am trying to do is have it so that if the "check box" is UN-checked it will remove the line that it just added to the Memo box. I have been able to get it to undo everything in the Memo box, but what I really need is for it to just undo the last line of text that was enterd when the user checked the box.
Example:
Memo Box:
This is the line that the checkbox just added when the checkbox is set to "True"
This is the test data the user has already put in the box...
==================
User now UN-checks the checkbox (I want the Memo box to read.. see below) Thereby deleting the line "This is the line that the checkbox just added when the checkbox is set to "True""
Memo Box:
This is the test data the user has already put in the box...
How can I accomplish this?
View 1 Replies
View Related
Nov 14, 2006
Hi, I have found the answer to most of my problem, thanks to previous posts.
I am using the Undo command on a Date field. However it seems that my code is maybe not staying on the event to action the undo.
After it runs the Focus goes to the next field Me.LeaveDays and the value is automatically entered, unless I comment back in the Goto's in which case the value will be zero.
I want to be able to Undo the EndDate (and preferable the StartDate, and Setfocus to StartDate) EndDate will do if not possible.
Don't want to Undo the whole form, although that could be a last resort.
My code is in the before_update event, image posted (ignore faded fields, not visible/needed in final solution)
Private Sub EndDate_BeforeUpdate(Cancel As Integer)
On Error GoTo Err_EndDate_BeforeUpdate
Dim intLeaveLeftAL As Integer
Dim intLeaveLeftSL As Integer
Dim intLeaveDays As Integer
Dim dtNullDate As Date
Dim varNullField As Variant
intLeaveLeftAL = Nz(Forms!frmAddLeaveRecords.fsubLeaveAgTots.Form![DailyALInc] - (Forms!frmAddLeaveRecords.fsubLeaveAgTots.Form![ALDays] - Forms!frmAddLeaveRecords.fsubLeaveAgTots.Form![ACDays]), 0)
intLeaveLeftSL = Nz(10 - Forms!frmAddLeaveRecords.fsubLeaveAgTots.Form![SLDays], 0)
' Use the WorkingDays function to calc the number of Leave Days
' set LeaveDays and requery the form
intLeaveDays = WorkingDays(Me.StartDate, Me.EndDate)
If Me.LCode = "LC41" Then ' Sick Leave
Select Case intLeaveDays
Case Is > intLeaveLeftSL
MsgBox "Employee does not have enough Leave" & vbCrLf & "to take as Sick Leave.", vbCritical + vbOKOnly + vbDefaultButton1, "Entry in Error"
varErrorCondition = True
Me.EndDate.Undo
GoTo Exit_EndDate_BeforeUpdate
Case Else:
End Select
ElseIf Me.LCode = "LC11" Or Me.LCode = "LC13c" Then ' Annual or C/Fwd Leave
Select Case intLeaveDays
Case Is > intLeaveLeftAL
MsgBox "Employee does not have enough Leave" & vbCrLf & "to take as Annual Leave.", vbCritical + vbOKOnly + vbDefaultButton1, "Entry in Error"
varErrorCondition = True
Me.EndDate.Undo
GoTo Exit_EndDate_BeforeUpdate
Case Else:
End Select
End If
Me.LeaveDays = intLeaveDays
Me.LeaveDays.Requery
varErrorCondition = False
Exit_EndDate_BeforeUpdate:
Exit Sub
Err_EndDate_BeforeUpdate:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_EndDate_BeforeUpdate
End Sub
The ifs and cases work fine, just like to send the User back a few steps
appreciated :) :)
View 9 Replies
View Related
Dec 16, 2004
I have what I think is a difficult problem to overcome...
I am designing a form to create an invoice. The user will select a workstream and a date range in form frmInvByHrs. Within this I want two sub-forms, one is frmInvByHrsTsht and the other is frmInvByHrsBill. I want the first one to display all the staff and their hours done, and the second one to be in data entry mode where you can enter the hours you want to bill. Each sub-form is based on a separate query.
Is it possible to do this? ie. to have one sub-form in data entry mode, and the other not? It seems to me that the data entry mode is controlled by the MAIN form regardless of the sub-form settings!
If this is not possible, do you know how I can acheive this?
Thanks
S
View 1 Replies
View Related
Nov 3, 2006
Hi everyone,
I have refined my query from previous threads to involved a module function. This calculates more acurately no of working days between dates and takes into account a holidays table. (All credit to Arvin Meyer on the module:) )
However because the Leave Year starts at the 1 July and finishes 30 Jun I need to compose the date for any current year Year(Now())
Enclosed scrdmp shows my query design. I can easily get it to work as you see it, but obviously as each year rolls over, the year needs to change.
Have looked at many posts but can't find what I'm looking for. This one will get me over the hurdle.
Many thanks,
View 6 Replies
View Related
Feb 10, 2005
Is there a way to code something that will say do Undo All changes.
I have a button called Exit without changes…and I would like to be able to undo everything that a user has just done on the form.
Thanks.
View 1 Replies
View Related
Aug 15, 2005
Hi All,
Is there a way that I can make a button which will undo all the changes being made on a form (on multiple records). I have a continious form with a checkbox after each record and want to restore the 'old values' if necessary.
Thanks.
I know it's possible by record, but the tricky part is to do this on multiple records.
View 2 Replies
View Related
Feb 17, 2006
We have an mdb back end on our server with read / write permissions for several approved users. One of them (don't know who yet) has converted the mdb file from 1997 to 2000. Is there a way to undo this? :o (a few have both versions on their machines which is why this was possible to begin to with)
We have had this set up for almost four years now, with no issues might I add but always knew in the back of my mind something like this would happen.
Thanks
View 1 Replies
View Related
Jun 22, 2005
I have a form with a subform, on the mainform there is an undo button but when someone makes changes on the subform the undo button wont run and the error message "The command or action Undo isn't available now". How can i get the mainform to detect that changes have been made on the subform and then if the button is clicked undo the changes.
View 4 Replies
View Related
Mar 21, 2006
I would like to be able to check to see if undo is available.
ie. i have a button thats called 'Cancel' When clicked it undo's changed and then closes the form, but if there are aren't any changes to undo it flags up an error saying not available.
I would still like it to close the form even if there are no changes to undo.
So check to see if the undo is available then undo and close if not then just close the form.
View 4 Replies
View Related
Jun 1, 2006
Hello All,
I am finding this one difficult so felt I should post my issue.
I have status field on my form. It is a bound field.
A combobox - inactive, active.
I wanted the field to do the following when changed
If change then msgbox = Please enter reason in activity notes
a vbYesCancel
If they select it calls the activity notes form - this portion works.
If they select cancel I tried making the field do
form.field.undo (Me.statusid.undo) - something similar
Cancel = True
to reset the field to the original state.
This fails and says my object is not valid
I would be happy to take any suggestions . As always thanks in advance.
View 1 Replies
View Related
Aug 30, 2006
Hello,
I use a listbox and a command button on a form as criteria to open another form.
The click event of my cmdbutton has the following code that runs after selecting a record in the listbox:
If IsNull(Me![NAME]) Then
MsgBox "Sorry! No record selected"
Exit Sub
End If
DoCmd.OpenForm ("myform")
I have now created a menu bar and would now like to remove the command button and place it somewhere that can run when I select the menu to open a specific form.
Basically I need that when I select a menu from my menu bar, the code should verify is a record in the listbox has been selected.
If yes, then it will open that form, if not it should run the undo command and not open the form but bring me back to the form on which is placed my listbox (frmEforms).
Any help? Thanks.
View 5 Replies
View Related
Apr 28, 2013
I have a form with an undo button which works fine...sometimes.
The issue is if the user hasn't clicked out of the text box they have updated before clicking the undo changes button only the changes they have made to that text box are un-done.
My question is when the user clicks the undo chnages button how do I code it so the changes to the whole form are undone even if they haven't clicked out of the last text box they updated.
View 4 Replies
View Related
Aug 17, 2011
I have a form that has multiple text boxes. Was trying to add an Undo button that behaves exactly the same as the (Ctrl+Z) or the undo button used in microsoft access, word, excel ..etc. as it only undos one action in a click. When added the undo button i used just a normal button and added a code to it. if i type in different text boxes and press on the undo button it undos everything modified since the form was opened. Is there a way to change that ?
View 5 Replies
View Related
Feb 14, 2007
hey,
i have applied a lookup wizard to some fields, just to see what happened, and now i want to undo it... how do i do this pls?
thanks
View 3 Replies
View Related
Jul 26, 2007
Hi, i am stumped.
I have two tables Tbl_Referrals and Tbl_CMSData. Both of these tables have an identifier in called ConflictID. I have created a query which selects the records from both tables where the conflict ID is the same.
I have a form running this query. Down one side of the form i have all the details from Tbl_CMSData and on the otherside of the Form i have the corresponding details from Tbl_Referrals. I need the user to be able to update field by field from Tbl_CMSData to TblReferrals. This is done by means of a simple update query for each field. This all works fine.
Problem - I need an undo button for each field. Me.Undo does not work becuase the changes have been made by a query and not on the form.
Is there a way of undoing what the query has updated? Possibly by setting the focus to a Tbl_Referrals and then undoing the changes?
Thanks in advance
View 5 Replies
View Related
Jan 27, 2005
Hi there,
I've a button that position the table on a new record:
DoCmd.GoToRecord , , acNewRec
And I create a button to cancel that action:
Me.Undo
But the code field (autoincrement) continues autoincrementing! Explaning:
1. I click on "Add" button
2. The table's positioned on autoincrement code #1
3. I click on "Cancel" button
4. The register is cancelled, it isn't includded on table
5. I click on "Add" button
6. The table's positioned on autoincrement code #2 and the #1 isn't exists...
How it's happen? How I solve it?
Thanks
View 8 Replies
View Related
Mar 7, 2005
Hi
I have a form and a linked subform which are linked by Purchase Order Number. When items have been delivered on the purchase order, the user should update the continuous subform with the number of items that have been delivered. This works fine.
The problem I have is using an exit button that does not save any of the changes to either the data in the form or the subform. It doesn't matter if there is a prompt to alert the user that there have been changes made.
I have been messing around with DoCmd.RunCommand acCmdUndo in the on click event of my exit button which kind of works when changes has accidentally been made, but is very unsophisticated - any ideas?!
Thanks
Georgina
View 1 Replies
View Related
Nov 4, 2005
Hi,
Have a main form with subform. Can udo edits on the main form and am trying to do the same for the subform and am having problems. Can someone correct my syntax for me please..........and maybe someday I'll get it!
Here's my code below....thanx.
Private Sub PDEditUndoBut_Click()
On Error GoTo Err_PDEditUndoBut_Click
'Me.Label95.Visible = False
'Me.Label62.Visible = True
Beep
Me.Undo
Me.fmEmergency_Sub.Form.Undo
Exit_PDEditUndoBut_Click:
Exit Sub
Err_PDEditUndoBut_Click:
MsgBox Err.Number, Err.Description
Resume Exit_PDEditUndoBut_Click
End Sub
View 2 Replies
View Related
Jan 4, 2006
I have a main form (A) with a subform that is another form with a datasheet(A_SUB)
On the form A is an undo button which rewinds any changes that occur to A that I do not wish to commit. However when I make a change to A_SUB the changes are not rewound. I considered implementing an UNDO for A_SUB but this is messy. What would be a better solution?
View 2 Replies
View Related
May 2, 2006
Hi,
I have a question.
How can I make undo delete records?
When the user select all the records, and then click "delete" key. Then it will delete all records.
I want to setup that there must be at least 1 record left.
If they select all the records and delete all, then it will undo delete all records. We have to keep at least 1 record.
What command to undo delete all records?
Please let me know, thanks.
View 3 Replies
View Related
Jun 19, 2006
If quantity requird less than stock qty don't accept record by delete or undo the record . how to do it without deleting the table data ?
View 3 Replies
View Related
Jan 7, 2008
Hi everyone! Well, I goofed... I was trying to figure out how cause access to launch a switchboard I made and NOT launch the regular shortcut bars or database window. Well, fortunately the help file told me I could change that in tools...startup options...
I found it, and it worked great, except I can't get back into my regular shortcut menu features, including the startup options themselves to reverse it. I did figure out I could reclaim the database window by pushing f11, but sadly have been unable to figure out how to get to my shortcut menus and back into startup options. Anyone know how I can get back in?
Next time I'll have to make a copy before doing that...
View 1 Replies
View Related
Sep 27, 2005
Could someone look at my code and tell me why my “Me.TargetDate.Undo” won’t work?
First, let me say that the TargetDate field has an On-Click event that calls a module written by Allen Browne), which is shown below and works great.
=CalendarFor([TargetDate],"Select a date from the calendar ")
What happens is that the Me.TargetDate.Undo event always keeps the date selected in the calendar.
Based on something I read from Rual Guy on another issue, I’ve used the TargetDate_LostFocus routine to check for some additional data entry errors. I’ve tried moving the code in “Private Sub TargetDate_Exit(Cancel As Integer)” to the LostFocus, but it doesn’t make any difference to the Undo. I’ve also tried “I’ve tried “Private Sub TargetDate_Change(),Me.Undo…” but that doesn’t work either. :confused:
Private Sub TargetDate_Enter()
If Not IsNull(Me.TargetDate) Then
OldTarget = Me.TargetDate
End If
End Sub
Private Sub TargetDate_Exit(Cancel As Integer)
If Not IsNull(Me.TargetDate) Then
If DateDiff("d", Me.DateOpened, Me.TargetDate) < 0 Then
MsgBox "You have selected a date that is before…bla bla"
Me.TargetDate.Undo
Me.TargetDate.SetFocus
ElseIf DateDiff("d", Date, Me.TargetDate) < 0 Then
MsgBox "You have selected a date that is prior to today's date…bla bla"
Me.TargetDate.Undo
Me.TargetDate.SetFocus
ElseIf Weekday(Me.TargetDate) = 1 Or Weekday(Me.TargetDate) = 7 Then
MsgBox "You have selected a date that falls on a weekend..bla bla"
Me.TargetDate.Undo
Me.TargetDate.SetFocus
End If
End If
End Sub
Private Sub TargetDate_LostFocus()
If Me.TargetDate > OldTarget And Me.cboAssignToID <> OldAssignee Then
MsgBox "The target date can only be changed if …bla bla"
Me.TargetDate.Undo
Me.TargetDate.SetFocus
End If
End Sub
Ever thankful for this forum,
Christine
View 1 Replies
View Related
Nov 10, 2006
I have a small procedure I'd like to include in my database. I want to confirm with the user with some sort of modal popup message (I think that's the right term) when they abort data entry on a form (anywhere on that form which consists of several pages, and a linked subform on one page). I think I can use the "on undo" event, but I don't know what code to include to make this happen...
Tried searching for this to no avail, but I would think this is a common procedure to prevent users from accidental data entry abortion.
Thanks,
Brad
View 4 Replies
View Related