Learn Microsoft Access Advanced Programming Techniques, Tips and Tricks.

deleting data

Introduction

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.

Cascade Delete Option

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 relationship 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

  1. Installing the Personal Web Server (PWS)
  2. or Internet Information Services (IIS)
  3. Create the Example ASP Files
  4. Create a DSN Connection
  5. Connect to the Database
  6. Modify Access Data Online
  7. Inserting Data
  8. Modifying Data
  9. Deleting Data
  10. Data Insert Form
Share:

No comments:

Post a Comment

Comments subject to moderation before publishing.

PRESENTATION: ACCESS USER GROUPS (EUROPE)

Translate

PageRank

Post Feed


Search

Popular Posts

Blog Archive

Powered by Blogger.

Labels

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