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

Delete a record based on a value entered by the user and display therest of the records

Hi,

I would like to delete a record based on a user entered string. Here
are the
details. I have a txtFind textbox. A string is entered by the user.
Based on
that string value it displays that one record in the fields in the
frmDeleteComponent form. There is also a lstDelete listBox which
displays all
the record. But for some reason it does not delete that particular
record as
requested by the user. I have written the sequence I am following and
I am
hoping that someon is able to answer my question. I need help.

Thanks,
SA
'================================
My code in frmDeleteComponent:
'================================
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

Dim stDocName As String

Dim Msg, Style, Title, response
Msg = "Do you wish to Delete This Component?"
Style = vbYesNo + vbExclamation
Title = "Delete Component Confiramtion"
response = MsgBox(Msg, Style, Title)

If response = vbYes Then
stDocName = "macroDelete"
DoCmd.RunMacro stDocName
End If

Exit_cmdDelete_Click:
Exit Sub

Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_cmdDelete_Click

End Sub

'**************************************

Private Sub cmdFind_Click()
On Error GoTo Err_cmdFind_Click

DoCmd.GoToControl txtPartNumber.Name
DoCmd.FindRecord Me.txtFind.Value, acEntire, False, acSearchAll,
True,
acCurrent, True

Exit_cmdFind_Click:
Exit Sub

Err_cmdFind_Click:
MsgBox Err.Description
Resume Exit_cmdFind_Click

End Sub
'====================================
Details of macroDelete:

Action:
1 SetWarnings
2 OpenQuery
3 RunMacro
4 Close
5 OpenForm

Details
----------
1 SetWarning: is set to No
2 OpenQuery: calls queryDelete ; View: datasheet; dataMode: Edit
Here's the sql statement:
DELETE tblParts.*, "PartNumber" AS Expr1
FROM tblParts
WHERE ((("PartNumber")="txtFind"));
3 runMacro: runs another macro called MacroDeleteDisplay with
repeatCount
set to
Action: GoToControl: lstDelete
RunCommand: Refresh
4 Close: Actually closes the frmDeleteComponent (I have included the
code
from that form above)
5 OpenForm: frmDeleteComponent; View:Form; Window Mode: Dialog
Jun 27 '08 #1
5 1905
Try something like this in a command button:

Private Sub Command1_Click()
DoCmd.SetWarnings False
If MsgBox("Do you want to delete this record?",vbYesNo, "Delete Record
Yes/No") = vbYes Then
DoCmd.RunSql "Delete * From tblPars Where PartNumber = '" & txtFind &
"'"
End If
DoCmd.SetWarnings True
End If

Note: to make the code more readable - you may want to rename txtFind as
txtPartNumber. Also, when using parameters in a query as above - you
have to delimit the parameter with single quotes ' ' if it is a string.
In Jet sql -- data parameters are delimted with the # symbol. Number do
not require delimiting. I also temporarily disabled the default
warnings message and then re-enable it at the end of the procedure.
Otherwise you will get the default message everytime you delete
something:

1 Record is about to be deleted. Continue Yes/No?

You already have a custom message with the If MsgBox(...) statement.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #2
Correction: Date Parameters #3/25/2007# require the # symbol as the
delimeter in Jet Sql. Most sql languages use the single quotes ' ' for
delimiting dates the same as strings. That I know, only Jet sql (Access
Jet sql) uses the # symbol for delimiting dates.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #3
On May 19, 12:17*pm, Rich P <rpng...@aol.comwrote:
Try something like this in a command button:

Private Sub Command1_Click()
DoCmd.SetWarnings False
If MsgBox("Do you want to delete this record?",vbYesNo, "Delete Record
Yes/No") = vbYes Then
* DoCmd.RunSql "Delete * From tblPars Where PartNumber = '" & txtFind &
"'"
End If
DoCmd.SetWarnings True
End If

Note: to make the code more readable - you may want to rename txtFind as
txtPartNumber. *Also, when using parameters in a query as above - you
have to delimit the parameter with single quotes ' ' if it is a string.
In Jet sql -- data parameters are delimted with the # symbol. *Number do
not require delimiting. *I also temporarily disabled the default
warnings message and then re-enable it at the end of the procedure.
Otherwise you will get the default message everytime you delete
something:

1 Record is about to be deleted. *Continue Yes/No?

You already have a custom message with the If MsgBox(...) statement.

Rich

*** Sent via Developersdexhttp://www.developersdex.com***

Well, I had one more question ---
how would I show all the records minus the deleted record in the
lstBox. I would like to refresh the lstBox with the right information.
Currently it is showing all the records.

Also, I would like to know what is wrong with the way I have set the
macro originally.

Thanks,
Sangeeta.

Jun 27 '08 #4
For general purpose operations - the built in macros are fairly ideal
because they don't require any maintenance. But if you need to
customize some operation - the macro is not the most ideal way to go
because they are not easy to customize. Thus, you would use VBA to
write custom procedures/functions.

As for "refreshing" your listbox with the current rows in your table -
just add this to the sample procedure:

Private Sub Command1_Click()
DoCmd.SetWarnings False
If MsgBox("Do you want to delete this record?",vbYesNo, "Delete Record
Yes/No") = vbYes Then
DoCmd.RunSql "Delete * From tblPars Where PartNumber = '" & txtFind &
"'"
End If
listbox1.Rowsource = "Select fldx From tblParts"
listbox1.Requery
Me.Requery
DoCmd.SetWarnings True

End If

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #5
On May 19, 2:15*pm, Rich P <rpng...@aol.comwrote:
For general purpose operations - the built in macros are fairly ideal
because they don't require any maintenance. *But if you need to
customize some operation - the macro is not the most ideal way to go
because they are not easy to customize. *Thus, you would use VBA to
write custom procedures/functions. *

As for "refreshing" your listbox with the current rows in your table -
just add this to the sample procedure:

Private Sub Command1_Click()
*DoCmd.SetWarnings False
*If MsgBox("Do you want to delete this record?",vbYesNo, "Delete Record
*Yes/No") = vbYes Then
* *DoCmd.RunSql "Delete * From tblPars Where PartNumber = '" & txtFind &
*"'"
*End If
*listbox1.Rowsource = "Select fldx From tblParts"
*listbox1.Requery
*Me.Requery
*DoCmd.SetWarnings True

End If

Rich

*** Sent via Developersdexhttp://www.developersdex.com***
Thank you for all your help. It works like magic.

SA
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
5
by: Sue | last post by:
As soon as a character is entered in the first field of a new record, the number of records shown in the navigation buttons increases by 1 and the new record button becomes enabled. In the...
7
by: Megan | last post by:
Hi everybody- I inherited a database that somehow uses a bound combo box as a record selector. Let me give you some background. The form is based on data from 2 tables. The first table, Person,...
17
by: (PeteCresswell) | last post by:
I've got apps where you *really* wouldn't want to delete certain items by accident, but the users just have to have a "Delete" button. My current strategies: Plan A:...
1
by: Richard | last post by:
A shipment of material is received. The shipment contains several items. Each item is assigned an internal tracking number for auditing purposes and further processed. The tracking number is...
3
by: bluez | last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record. ...
1
by: Bobby | last post by:
Hi I am using Access 2003 mdb as a front end to an application which uses SQL Server 2000 as the backend. The two are connected using ODBC. On one particular table (the Stock table), I have a...
1
by: jmarcrum | last post by:
Hello all! i have a “monitor-type” program, where my program recognizes my defined "commands”, and executes the given command, or produces an error message that says “unrecognized command”. After...
2
by: lhsiber | last post by:
I am new to access and am having a problem with filtering. Here is a little bit of my setup: I have a main form that has a listbox so that users can choose one or many groups in which to display...
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.