Suppress AfterUpdate event when duplicating a record?

kelsita_05

Registered User.
Local time
Today, 15:53
Joined
Aug 23, 2005
Messages
52
I have after update events on two form controls that check for duplicates and pop up a message to warn the user if a duplicate is found and runs a query to show them the dup. record. This works fine.

I've been asked to add a button to duplicate a record. I used the button wizard since that has worked well for me in the past. Problem is, when it duplicates the record, it throws the duplicate warning message box (twice) because technically those fields are duplicates, but the user will change them shortly.

Is there anyway I can turn off those events when I click the duplicate button? Or is there an alternate point when I can run the events? I tried LostFocus(but that checks ever single time you leave the field whether you've changed anything or not) and on Change (but as soon as you start typing it checks) and I got a VBA error when I tried on Dirty.

Thank you!
 
As part of your Duplicate Button, and given that the user is going to change the record any way, why not simply add an additional character to the relevant fields so that it is no longer a duplicate?
 
That sounded like a great solution and I was in the process of implementing it. And then I realized that the user may not actually change these two fields. They may need to stay as is.

Back to the drawing board?

Thank you though!
 
You could scrap the Textbox AfterUpdate events and check for duplicates using the Form_BeforeUpdate event. This would allow you to use the Wizard-generated Copy Button.

Or, you could use a custom Copy hack behind a Copy Button.
Code:
Private Sub CopyPartiaRecordl_Click()
  'Copy fields from original record to variables
   NewField1 = Me.YourField1
   NewField2 = Me.YourField2
   NewField3 = Me.YourField3

  'Go to a new record 
   DoCmd.GoToRecord , , acNewRec

  'Plug in old values from variables into new record
    Me.YourField1.Value = NewField1
    Me.YourField2.Value = NewField2
    Me.YourField3.Value = NewField3

End Sub
Simply exclude the Fields/Controls that have the Required Property set to Yes from the code.

Linq ;0)>
 
Last edited:
I believe you can programmatically enable and disable AfterUpdate event handling for a Textbox by modifying the AfterUpdate property. To enable event handling, set the property to "[Event Procedure]" and to disable event handling set the property to an empty string "". In addition you can set the AfterUpdate event to run a function by directly setting the AfterUpdate property to the name of the function, like "=YourFunction()"
 
My solution would have just to add a boolean flag and have the command button set it to true and the After Update event to check the flag first before it does its check. If it isn't false, it bypasses the checking code.
 
Thanks for all the good ideas - I ended up going with the Boolean flag, which is what I was trying to accomplish in my head but just couldn't quite figure out how to make it happen. Works great now!
 

Users who are viewing this thread

Back
Top Bottom