|
 |
|
Dev Articles Community Forums
> Databases
> Microsoft Access Development
|
Insert value from one form into several tables
Discuss Insert value from one form into several tables in the Microsoft Access Development forum on Dev Articles. Insert value from one form into several tables Microsoft Access Development forum to discuss problems and solutions with this popular DBMS. Use Access to build and modify database tables, or full-featured applications.
|
|
 |
|
|
|
|

Dev Articles Community Forums Sponsor:
|
|
|

July 11th, 2012, 02:58 AM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 8
Time spent in forums: 2 h 31 m 38 sec
Reputation Power: 0
|
|
|
Insert value from one form into several tables
HI
i need to insert value from one text box to several tables.
the user will insert the value on one text box and than will be able to press one of several buttons; each button will insert the value into different table.
so basically i need the code to insert value into table.
access 2003
Thanks for your help
Eyal
|

July 11th, 2012, 07:42 AM
|
|
Contributing User
|
|
Join Date: Mar 2006
Location: Zagreb - Croatia
Posts: 142
Time spent in forums: 2 Days 23 h 4 m 58 sec
Reputation Power: 8
|
|
|
You don't need the same data in two (or more) tables,
except the FOREIGN KEY.
|

July 12th, 2012, 01:24 AM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 8
Time spent in forums: 2 h 31 m 38 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by MStef You don't need the same data in two (or more) tables,
except the FOREIGN KEY. |
Hi
no, i do not need the same data in few tables.
i need that every time the user is typing text on the text box, he can choose a button to which table to insert it.
TNX
Eyal
|

July 13th, 2012, 04:21 AM
|
|
Contributing User
|
|
Join Date: Mar 2006
Location: Zagreb - Croatia
Posts: 142
Time spent in forums: 2 Days 23 h 4 m 58 sec
Reputation Power: 8
|
|
|
Try to do it via "APPEND QUERY".
|

July 17th, 2012, 08:36 AM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 1
Time spent in forums: 15 m 33 sec
Reputation Power: 0
|
|
|
Hi! All you have to do is
INSERT INTO tableName (field1, field2, field3...)
VALUES (value1, value2, value3...)
This is SQL. You need to construct the SQL sentence dinamically, depending on the button pressed.
Dim strTableAndFields as String ' Name of the table
Dim strSQL as String ' SQL command to insert
' ------ When user presses button1
strTableAndFields = "table1 (field1, field2, ....)"
'----- And later on
strSQL = "INSERT INTO " & strTableAndFields & " VALUES (" & control1 & ", " & control2 & .... & ")"
... where control1, control2... are the names of the controls that get the information to insert (you should make sure that they are not empty)
This would be the SQL command.
In order to embed SQL into your code (that is, into Visual Basic), you need to access the database through an object library like DAO or ADODB, then execute the SQL sentence.
* With DAO it's pretty straighforward:
Dim db as DAO.Database
Set db = CurrentDb()
' -- now the only thing you need to do is
db.execute strSQL
' -- where strSQL is the SQL command that you construct
I hope it's clear enough for you.
Regards
|

July 17th, 2012, 09:02 AM
|
|
Registered User
|
|
Join Date: Jun 2012
Posts: 8
Time spent in forums: 2 h 31 m 38 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by Clon1x Hi! All you have to do is
INSERT INTO tableName (field1, field2, field3...)
VALUES (value1, value2, value3...)
This is SQL. You need to construct the SQL sentence dinamically, depending on the button pressed.
Dim strTableAndFields as String ' Name of the table
Dim strSQL as String ' SQL command to insert
' ------ When user presses button1
strTableAndFields = "table1 (field1, field2, ....)"
'----- And later on
strSQL = "INSERT INTO " & strTableAndFields & " VALUES (" & control1 & ", " & control2 & .... & ")"
... where control1, control2... are the names of the controls that get the information to insert (you should make sure that they are not empty)
This would be the SQL command.
In order to embed SQL into your code (that is, into Visual Basic), you need to access the database through an object library like DAO or ADODB, then execute the SQL sentence.
* With DAO it's pretty straighforward:
Dim db as DAO.Database
Set db = CurrentDb()
' -- now the only thing you need to do is
db.execute strSQL
' -- where strSQL is the SQL command that you construct
I hope it's clear enough for you.
Regards |
Thanks
this will give me the first push start to do it.
BR
Eyal
|

July 19th, 2012, 12:57 AM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 1
Time spent in forums: 29 m 24 sec
Reputation Power: 0
|
|
|
Can primary key be useful instead of foreign key?
|

November 17th, 2012, 12:51 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 1
Time spent in forums: 22 m 11 sec
Reputation Power: 0
|
|
|
Hi dears,
please help me
I want to run this code in ms access 2003 form but it has a problem syntax error
this is the complete code
Private Sub add_Click()
Dim strSQL As String
strSQL = "INSERT INTO Table1 ("name,number) VALUES ('1',1);"
Dim db As DAO.Database
Set db = CurrentDb()
db.Execute strSQL
End Sub
thank you for any help ....
|

November 19th, 2012, 04:48 PM
|
 |
Contributing User
|
|
Join Date: Oct 2010
Location: The Great Land
Posts: 238
Time spent in forums: 2 Days 5 h 26 m 16 sec
Reputation Power: 3
|
|
|
shahab, you should have started a new thread with your question.
Hijacking thread is poor forum etiquette and your question has less chance of getting attention as simply another post in existing thread. Normally I would not view a thread that has been answered but this was the only new post in forum so I got curious.
There is an unnecessary quote mark in the sql string. Variables are ok but not always needed, especially for such short procedure.
Private Sub add_Click()
CurrentDb.Execute = "INSERT INTO Table1 (name, number) VALUES ('1', 1);"
End Sub
Last edited by June7 : November 19th, 2012 at 04:55 PM.
|

November 19th, 2012, 06:48 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 3
Time spent in forums: 6 m 8 sec
Reputation Power: 0
|
|
|
I want to run this code in ms access 2003 form but it has a problem syntax errorURLURLURLURL
URL
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|