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

Add Record

I am fairly new to MS Access and I am creating a simple database. I
have created a form that has information from a three different tables
displayed in three different list boxes(listbox1, listbox2,
listbox3). I then have a text box and button under each list box
(textbox1, textbox2, textbox3, button1, button2, button3). There are
also other fields on the form that contain information(Index Number,
Fiscal Year)

I would like to be able to enter a a string into textbox1 and click
the button (or press enter) and have it add a record to table1 that
includes the string from textbox1, Index Number and Fiscal Year. It
should ten clear textbox1 and update listbox1.

This would be repeated for the other 2 tables with one addition, I
need to add the current date to #3.

I also want the ability to double click an entry in listbox1 and have
it populate textbox1 with the information for editing. After editing
the information, you should be able to click the button or hit enter
and have it update the table and requery the listbox.

I also want the ability to highlight an entry in listbox1 and click a
delete button which would delete the entry from table1 with a
confirmation.

Please let me know how I can do these things.

Thanks.
Aug 16 '08 #1
2 3239
Your command buttons will execute action queries to INSERT or DELETE the
record in the appropriate table.

The basic idea for the insert will be:

Private Sub button1_Click()
Dim db As DAO.Database
Dim strSql As String

If IsNull(Me.textbox1) Then
MsgBox "Say what?"
Else
Set db = dbEngine(0)(0)
strSql = "INSERT INTO ...
db.Execute strSql, dbFailOnError
Set db = Nothing
End If
End Sub

To get the SQL statement:
1. Mock up a query without any table.
2. Change it to an Append query (Append on Query menu)
3. Type some value (e.g. 99) into the Field row in query design, for each
field you want to insert.
4. Switch the query to SQL View (View menu.)
There's an example of the string you need to create.

You will concatenate the actual values into the string, e.g.:
strSql = "INSERT ... """ & Me.textbox1 & """, ...

Those extra quotes are needed for text fields. Explained here:
http://allenbrowne.com/casu-17.html

For more info on what it means to Execute an action query:
http://allenbrowne.com/ser-60.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"iwasinnihon" <iw*********@gmail.comwrote in message
news:b9**********************************@u6g2000p rc.googlegroups.com...
>I am fairly new to MS Access and I am creating a simple database. I
have created a form that has information from a three different tables
displayed in three different list boxes(listbox1, listbox2,
listbox3). I then have a text box and button under each list box
(textbox1, textbox2, textbox3, button1, button2, button3). There are
also other fields on the form that contain information(Index Number,
Fiscal Year)

I would like to be able to enter a a string into textbox1 and click
the button (or press enter) and have it add a record to table1 that
includes the string from textbox1, Index Number and Fiscal Year. It
should ten clear textbox1 and update listbox1.

This would be repeated for the other 2 tables with one addition, I
need to add the current date to #3.

I also want the ability to double click an entry in listbox1 and have
it populate textbox1 with the information for editing. After editing
the information, you should be able to click the button or hit enter
and have it update the table and requery the listbox.

I also want the ability to highlight an entry in listbox1 and click a
delete button which would delete the entry from table1 with a
confirmation.

Please let me know how I can do these things.

Thanks.
Aug 17 '08 #2
Thank you

On Aug 16, 7:44 pm, "Allen Browne" <AllenBro...@SeeSig.Invalidwrote:
Your command buttons will execute action queries to INSERT or DELETE the
record in the appropriate table.

The basic idea for the insert will be:

Private Sub button1_Click()
Dim db As DAO.Database
Dim strSql As String

If IsNull(Me.textbox1) Then
MsgBox "Say what?"
Else
Set db = dbEngine(0)(0)
strSql = "INSERT INTO ...
db.Execute strSql, dbFailOnError
Set db = Nothing
End If
End Sub

To get the SQL statement:
1. Mock up a query without any table.
2. Change it to an Append query (Append on Query menu)
3. Type some value (e.g. 99) into the Field row in query design, for each
field you want to insert.
4. Switch the query to SQL View (View menu.)
There's an example of the string you need to create.

You will concatenate the actual values into the string, e.g.:
strSql = "INSERT ... """ & Me.textbox1 & """, ...

Those extra quotes are needed for text fields. Explained here:
http://allenbrowne.com/casu-17.html

For more info on what it means to Execute an action query:
http://allenbrowne.com/ser-60.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"iwasinnihon" <iwasinni...@gmail.comwrote in message

news:b9**********************************@u6g2000p rc.googlegroups.com...
I am fairly new to MS Access and I am creating a simple database. I
have created a form that has information from a three different tables
displayed in three different list boxes(listbox1, listbox2,
listbox3). I then have a text box and button under each list box
(textbox1, textbox2, textbox3, button1, button2, button3). There are
also other fields on the form that contain information(Index Number,
Fiscal Year)
I would like to be able to enter a a string into textbox1 and click
the button (or press enter) and have it add a record to table1 that
includes the string from textbox1, Index Number and Fiscal Year. It
should ten clear textbox1 and update listbox1.
This would be repeated for the other 2 tables with one addition, I
need to add the current date to #3.
I also want the ability to double click an entry in listbox1 and have
it populate textbox1 with the information for editing. After editing
the information, you should be able to click the button or hit enter
and have it update the table and requery the listbox.
I also want the ability to highlight an entry in listbox1 and click a
delete button which would delete the entry from table1 with a
confirmation.
Please let me know how I can do these things.
Thanks.
Aug 18 '08 #3

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

Similar topics

4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
8
by: mark | last post by:
Access2000 How do I write a query that combines the CTC field from each record below into one record? I need to concatenate the CTC field with a separator, like below: ...
15
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
5
by: Ross A. Finlayson | last post by:
Hi, I'm scratching together an Access database. The development box is Office 95, the deployment box Office 2003. So anyways I am griping about forms and global variables. Say for example...
0
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
1
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
2
by: Mark Reed | last post by:
Hi All, I have created a multi-user application at work which is working perfectly apart from a small problem which I believe to more a of a user issue (maybe some will set me straight on that...
11
khalidbaloch
by: khalidbaloch | last post by:
hi : all Friend i am a new member of this comunity as well in php myqsl i want learn that how to dispaly three or two record from a mysql table for example .. mysql table category has 21 columns,...
3
prn
by: prn | last post by:
Hi folks, I've got something that's driving me crazy here. If you don't want to read a long explanation, this is not the post for you. My problematic Access app is a DB for keeping track of...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.