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

Add and/or delete records

I want to add a command button which will add a record to an Access table.

I would also like to add another command button which will delete a record
from the same table.
I searched Google for ideas how to do this but came up empty.

Any Idea how to do it.

Thanks
Jul 5 '06 #1
2 1731
AP
Probably the easiest way to do this is to turn on your wizards and use
the command button wizard.

Select record operations from the Categories, then Add New Record from
the Action. For Delete choose delete record from the same area.

AP

RICHARD BROMBERG wrote:
I want to add a command button which will add a record to an Access table.

I would also like to add another command button which will delete a record
from the same table.
I searched Google for ideas how to do this but came up empty.

Any Idea how to do it.

Thanks
Jul 5 '06 #2
Hi Richard,

Your request is a little general, so I will give you an example how you
can programatically insert a record/row into a table in access. The
scenario is that you have a data entry form with a number of textboxes
where a data entry person can enter text, dates and numreric data.

Say you have a firstname field, lastname field, entrydate field, amount
field. After the textboxes are populated you can insert the row into a
table like this:

Private Sub button1_Click()
Dim strSql As String
strSql = "Insert Into tblX(firtsName, LastName, EntryDate, Amount) " _
& "Values('" & txtFirstName & "', '" & txtLastName & "', #" &
txtEntryDate & "#, " & txtAmount

DoCmd.RunSql strSql
End Sub

In Access you have to delimit text values in a sql string with single
quotes. You delimit date values with the # symbol. Numeric values
don't require any delimiters.

To delete a specific row you need to specify a Where clause in your sql
statement so that you only delete the desired row:

strSql = "Delete From tblX Where ID = " & txtID
DoCmd.RunSql strSql

This assumes that your table has an ID column (like an Autonumber
field). Or you could delete multiple rows like this:

strSql = "Delete from tblX Where FirstName = '" & txtFirstName & "'"

Say you want to remove all rows where firstname = 'Bill'. Note that I
don't use delimeters for the ID field since it is numeric (autonumber
field). But I have to delimit FirstName with single quotes since it is
a text field.

HTH,
Rich
*** Sent via Developersdex http://www.developersdex.com ***
Jul 5 '06 #3

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

Similar topics

5
by: Alex | last post by:
Hi, hi have a table with 2.5 million records which i try do delete. i have several constraints on it too. i tried to delete the records using delete but it does not seem to work. the delete runs...
9
by: Robert Schneider | last post by:
Hi to all, I don't understand that: I try to delete a record via JDBC. But I always get the error SQL7008 with the error code 3. It seems that this has something to do with journaling, since the...
6
by: Paul T. Rong | last post by:
Dear all, Here is my problem: There is a table "products" in my access database, since some of the products are out of date and stopped manufacture, I would like to delete those PRODUCTS from...
8
by: John Baker | last post by:
Hi: Access 2000 W98! I have a table with numerous records in it, and am attempting to delete certain records that have been selected from it. These are selected based on the ID number in a...
3
by: Tim Marshall | last post by:
HI all, Access 2003, Jet back end. Rather than annoy my users in a particular app by having relationships with enforced relational integrity refuse to delete a record with related records, I'm...
2
by: Cornelius Buschka | last post by:
Hi, we saw the following problem: We deleted all rows from a table B referencing table A (~500000 records). No problem, but the following try to delete all records from table A (~180000) lead...
6
by: satish mullapudi | last post by:
Hi All, I am getting strange situation. These r the steps I have followed: 1. Created an EMPLOYEE table with around 14 fields & 688038 records. (so a large table indeed). 2. Tried to delete all...
2
kcdoell
by: kcdoell | last post by:
Hello I have a code where I want to delete the records that are found in my DAO recordset. I took a stab at this for the first time and got it to work but it is only delete one record at a time. If...
6
by: scott.tang | last post by:
I'm experiencing a very strange problem. My application is MS Access front-end and MS SQL server back-end database. I have a SQL statement that deletes records from a table after an export...
5
WyvsEyeView
by: WyvsEyeView | last post by:
Upon clicking Delete to delete the current record on frmTopics, I want several things to happen: 1) Display a custom message rather than Access's standard "You are about to delete n records" one....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.