Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert into multiple tables

Status
Not open for further replies.

unreal

Programmer
Jun 28, 2001
8
0
0
CA
can anybody help?
I have a form with information that elongs to 2 diferent tables in a database how jdo I write the sql statement for the information to go to its proper table.
I've tried a whole bunh of diferent statements but they don't work.Help would be much apreciated.
Thanks in advance
unreal
 
The only way I know is to write an "INSERT INTO" SQL statement for each table you want to add to:

'create DAO objects (do in a module)
Public ws As Workspace
Public db As Database

'Get default workspace (do on your form)
Set ws = Workspaces(0)
'Open the database
Set db = ws.OpenDatabase("c:\mydb.mdb", False, False, _ dbLangGeneral & ";pwd=baddog")
db.Execute "INSERT INTO table1(field1, field2) VALUES ('" & dbcFirst.Text & "','" & dbcSecond.Text & "');"
db.Execute "INSERT INTO table2 (field1, field2) VALUES ('" & dbcThird.Text & "','" & dbcFourth.Text & "');"


notes:
1) The syntax of the single and double quotes is hairy
2) I have not had good luck splitting an SQL statement to multiple line, just let it be long.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top