473,386 Members | 1,706 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,386 software developers and data experts.

How to Re-apply a filter on delete?

122 100+
I have a form (frmEditCategories) containing a sub-form (subCategories) that allows the user to add, delete, and change information that categorizes inventory items. The main form is not bound, and there is no parent/child relationship between the main form and the subform. I did this because every other form the users deal with have a form/subform set-up, and they are comfortable editing, deleting, and navigating within that setup.

I have code in the onDelete event of the subform that checks to make sure the record isn't referenced anywhere else before allowing it to be deleted. If a reference exists, then the user is prompted if they would like to mark it as inactive instead of deleting it. If they click yes, the field [Inactive] is set to True. By default, the sub-form is filtered so that inactive categories are not displayed.

What I would like to have happen is, when one or more records are made inactive (from the code in the sub-form's onDelete event) the filter should be reapplied so that record is no longer visible. The code is below:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Delete(Cancel As Integer)
  2.   If [Reserved] Then
  3.     MsgBox "This category is reserved by the system and can not be deleted.", vbOKOnly
  4.     Cancel = True
  5.   ElseIf DCount(1, "tblSalesSection", "SectionCategory = " & [CategoryID]) > 0 Then
  6.     rVal = MsgBox("The category '" & [ShortName] & "' is in use and cannot be deleted. Would you like to make it inactive?", vbYesNo)
  7.     If rVal = vbYes Then
  8.       [Inactive] = True
  9.     End If
  10.     Me.Requery
  11.     Cancel = True
  12.   End If
  13.   Cancel = True
  14. End Sub
The Me.Requery line is throwing an error: "Error 3246: Operation not supported in transactions." I think I understand what it means about transactions, being in the middle of a delete operation at the time. But I can't think of how to get around it. Any advice would be appreciated.
Nov 22 '10 #1
4 2523
NeoPa
32,556 Expert Mod 16PB
I think you'll find that the event procedure you need for the .Requery call is Form_AfterDelConfirm().

I'll warn you, as I feel bound to warn all those unfortunate enough to think managing data using unbound forms a good idea, that proceeding along those lines is guaranteed to give you headaches sooner or later. Sorry if this sounds patronising. It's not meant to. I express myself this way as I do have a fair bit of experience and can be expected to know what I'm talking about in this arena.

That said, I can only offer advice. You are of course fully at liberty to ignore it if you choose to, but at least other people reading this thread will see the advice anyway, so my responsibility is covered.
Nov 22 '10 #2
gershwyn
122 100+
Thank you for the response, NeoPa.

My understanding is that the AfterDelConfirm event will not fire if the delete event was canceled, which is the case here. I only allow the record to be deleted if it is truly not being used anywhere else. I put in a .Requery statement with a break on it and execution never reached that point.

As for your advice, I should point out the unbound form is merely a container for the subform and a handful of command buttons - no data. All the data is managed by the subform, which is bound to the underlying table.
Nov 22 '10 #3
NeoPa
32,556 Expert Mod 16PB
Ah. The advice was specifically for unbound forms that manage data (re Para #2). If that is not your situation then ignore the advice entirely safely.

As for the event procedure, what you say is perfectly true. I rather assumed you wanted it after a deletion was successful, as typically there would be no cause to requery at all if the deletion didn't go ahead.

I'm afraid if the deletion is canceled then there is no event there to trigger any code, not only as far as Access goes, but also logically as far as I can see. Why would there be an event for when nothing happens.
Nov 23 '10 #4
TheSmileyCoder
2,322 Expert Mod 2GB
I do remember a similar problem. At a time I was looking for an After-Delete action. What I did, was this:
Expand|Select|Wrap|Line Numbers
  1. Private bDeleting as Boolean
  2.  
  3. Private sub btn_Delete()
  4. 'Code for deletion would go here
  5.  
  6. 'Code for delayed event
  7.   bDeleting=true
  8.   'Engage delayed event
  9.   Me.TimerInterval=100
  10. End Sub
  11.  
  12. Private Sub Form_Timer()
  13.   if bDeleting Then
  14.     'Reset timer (turn it off)
  15.     Me.TimerInterval=0
  16.     Me.Requery
  17.   End if
  18. End Sub
  19.  
The reason for the bDeleting is that I have more then 1 delayed event. It is not strictly necessary.
Nov 23 '10 #5

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

Similar topics

1
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would...
4
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
1
by: Chris | last post by:
Sorry to post so much code all at once but I'm banging my head against the wall trying to get this to work! Does anyone have any idea where I'm going wrong? Thanks in advance and sorry again...
11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
1
by: James | last post by:
Hi, I would like to run a custom script on a linux box via a button on a php page (php webpage hosted on the same linux box). Is this possible? If so , can you give me a pointer in the right...
4
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function...
1
by: John Ryan | last post by:
What PHP code would I use to check if submitted sites to my directory actually exist?? I want to use something that can return the server code to me, ie HTTP 300 OK, or whatever. Can I do this with...
10
by: James | last post by:
What is the best method for creating a Web Page that uses both PHP and HTML ? <HTML> BLA BLA BLA BLA BLA
8
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
3
by: David Hickman | last post by:
Hi all, This is a newbie question but I have been struggling with this for ages. I have a document with 2 separate <?php sections of code. I would like to declare some variables in the first...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.