Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 11th, 2012, 02:58 AM
testeron testeron is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 8 testeron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old July 11th, 2012, 07:42 AM
MStef MStef is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Location: Zagreb - Croatia
Posts: 142 MStef User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 23 h 4 m 58 sec
Reputation Power: 9
You don't need the same data in two (or more) tables,
except the FOREIGN KEY.

Reply With Quote
  #3  
Old July 12th, 2012, 01:24 AM
testeron testeron is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 8 testeron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #4  
Old July 13th, 2012, 04:21 AM
MStef MStef is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Location: Zagreb - Croatia
Posts: 142 MStef User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 23 h 4 m 58 sec
Reputation Power: 9
Try to do it via "APPEND QUERY".

Reply With Quote
  #5  
Old July 17th, 2012, 08:36 AM
Clon1x Clon1x is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 1 Clon1x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #6  
Old July 17th, 2012, 09:02 AM
testeron testeron is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 8 testeron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #7  
Old July 19th, 2012, 12:57 AM
BarronBrad BarronBrad is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 1 BarronBrad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 24 sec
Reputation Power: 0
Can primary key be useful instead of foreign key?

Reply With Quote
  #8  
Old November 17th, 2012, 12:51 AM
shahab H.kaka shahab H.kaka is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 shahab H.kaka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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 ....

Reply With Quote
  #9  
Old November 19th, 2012, 04:48 PM
June7's Avatar
June7 June7 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2010
Location: The Great Land
Posts: 256 June7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 9 h 29 m 29 sec
Reputation Power: 4
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
__________________
I like to know if my suggestion helped you. One way to let me know is by clicking scales at top right corner of post.
Debug!Debug!Debug!http://www.cpearson.com/excel/debug.htm

Last edited by June7 : November 19th, 2012 at 04:55 PM.

Reply With Quote
  #10  
Old November 19th, 2012, 06:48 PM
Rhon3da Rhon3da is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 Rhon3da User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > Insert value from one form into several tables


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap