Ms-Access Advanced VBA Programming Techniques, Tips and Tricks.

deleting data

Deleting really requires more thought in real-world applications than we will demonstrate here. Instead of deleting data, consider archiving it in a different table for historical purposes. Or you might simply flag a record as inactive without actually removing it from the database. Actually deleting data is a permanent solution, so approach it with caution.

Here we use the final two scripts. As with modifying, deleting first requires that you ascertain that a given field is available. So the first script, delete_select.asp, displays a list of discontinued products from the Northwind database's Products table. Clicking that product will execute delete.asp, which actually deletes the record from the table. But before doing so, we must turn on the Cascade Delete option in the relationship between the Products table and the Order Details table. Otherwise the script will return an error. To do so, open the Northwind database in Access and:

  1. Click the Relationships button to open the Relationships window.
  2. Right-click the join line between the Products and Order Details tables.
  3. Choose Edit Relationships from the resulting submenu.
  4. In the Edit Relationships dialog box, check the "Cascade delete related records" option.
  5. Click OK, close the relationships window, and save the database.

This is an accommodation to simplify the example. When making deletions in a real application, it is better not to permanently turn on the cascade Delete option. Such a drastic step might destroy valid corresponding data in the Order Details table, and just because you are discontinuing the item doesn't mean that you never actually supplied it to a customer. So let this simplified example demonstrate how far seemingly simple decisions can reach.

That said, you are ready to delete some data. Point your browser to the following URL: http://localhost/sample/delete_select.asp

You should see a list of discontinued products, which delete_select.asp generates by selecting from Products where Discontinued=True. Notice that this time, the page isn't an HTML form instead, each product is simply a link with delete.asp and an appended ProductID value for its href.

Click any item to delete it from the Products table (and any corresponding records from the Order Details table). This executes delete.asp, which grabs the < ProductID value from the URL as Request.QueryString("ProductID")

Using this value, it constructs a Delete SQL statement, executes it, and confirms with the message:The record has been deleted.

Opening the Products table in Access should reveal that the record is indeed gone.

Click Next for insert-form.html

Share:

No comments:

Post a Comment

Trending

Popular Posts

Search This Blog

Blog Archive

Powered by Blogger.

Labels

Forms How Tos MS-Access Security Functions Reports Animations msaccess animation msaccess forms Utilities msaccess controls Access and Internet MS-Access Scurity MS-Access and Internet Queries External Links msaccess reports msaccess tips Menus and Toolbars Accesstips MsaccessLinks Process Controls Art Work Downloads msaccess How Tos Graph Charts msaccessQuery List Boxes Command Buttons Emails and Alerts Query Combo Boxes Custom Wizards msaccess graphs msaccess reporttricks ms-access functions msaccessprocess security advanced Access Security DOS Commands Data Macros Menus Property Report Top Values VBA msaccess email msaccess menus progressmeter Access2007 Array Auto-Number Command Button Join Microsoft Numbering System Records Security Split SubForm Table Utility Workgroup database msaccess functions msaccess wizards Access2003 Accounting Year Action Animation Attachment Binary Numbers Budgeting Calculation ChDir Color Palette Conditional Formatting Controls Copy Custom Functions Data Filtering Data Type Defining Pages Diagram Disk Dynamic Lookup Error Handler Excel Export Expression External Field Type Fields Filter Form Form Instances Formatting Groups Hexadecimal Numbers Import Labels List Logo Macro Mail Merge Main Form Memo Methods Monitoring Object Reference Objects Octal Numbers Operating System Paste Primary-Key Product Rank Reading Rich Text Sequence SetFocus Summary Tab-Page Time Difference Union Query User Users Variables Water-Mark Word automatically commands function hyperlinks iSeries Date iif ms-access msaccess msaccess alerts pdf files reference restore switch text toolbar tutorial updating upload vba code

Featured Post

Finding Last Day of Week

How to find the week-end date or first-day date of a week using Current Date as input.  Or find first/last-day date of any week by giving a ...

Labels

Blog Archive

Recent Posts