Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 7th, 2010, 07:10 PM
Registered User
 
Join Date: Apr 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Delete Query using IF statement

The problem I am having is that, the if statement does not seem to be correct as it’s not actually checking to match up a claim # for one table and matching it to another. If there is a match then it’s supposed to run a delete query to remove all these matches. If there is a discrepancy it’s supposed to preview the claims that the claim # does not match up

Private Sub Delete_Claim_CMD_Click()
'matches records and deletes ones that have been inputted into the Customer Return Database
Dim stDocname As String
stDocname = "RptAllCustRet"
'Matches up claim number on the master list and the OP Customer returns
If [tbl_master_data]![RPT_CLAIM_NO] = [TblAllCustRet]![RPT_CLAIM_NO] Then
'Runs the query to delete all non matching / missing / complete claims
DoCmd.OpenQuery (DeleteClaim)
ElseIf [tbl_master_data]![RPT_CLAIM_NO] <> [TblAllCustRet]![RPT_CLAIM_NO] Then
' Opens the report to show the incomplete claims
DoCmd.OpenReport stdDocName, acPreview
End If

End Sub

My delete query works but it removes all fields once run

Also one more thing since I am at it
I am looking for a command line that will do this
Query to find a field “metric flag” ‘M’ and a weight  done
Now I want to convert this weight only flagged with the “M”
If Metric_Flag = “M” then Bundle_Weight = Bundle_Weight*2.20
Is this possible?
 
Old April 9th, 2010, 08:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

By looking at your code, I see a lot of potential problems.

First, where is this code located? It looks like it's a button on your form called Delete_Claim_CMD. It also looks like the code is run when someone clicks on the button.

If so, which table is the record source for your form? Is it tbl_master_data or TblAllCustRet or something else or nothing (an unbound form)?

Which tables are open at the time the person clicks the button? Is there another form open that has another table as its record source? Is the code you posted mentioning tables that are not open by any form at all at the time the user clicks the button?

Putting a criteria in your query in the claim number field mentioning any open form's record's claim number value will also simplify the code. But I'd have to know which form is open when the query is run.

The answers to these questions will determine what your code should look like.
__________________
Greg Serrano
Michigan Dept. of Environmental Quality
Air Quality Division





Similar Threads
Thread Thread Starter Forum Replies Last Post
php/mysql delete button and delete query dungey PHP Databases 17 April 11th, 2009 12:24 PM
problem with delete statement thas123 SQL Server 2000 6 March 23rd, 2006 01:13 PM
Delete Statement Error Jane SQL Language 1 October 21st, 2005 01:45 PM
T-SQL Delete statement Alcapone C# 3 November 3rd, 2004 01:08 PM
sql delete statement sand133 VB Databases Basics 2 July 7th, 2004 10:56 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.