PC Review


Reply
Thread Tools Rate Thread

INSERT INTO multiple tables

 
 
James Hartrich
Guest
Posts: n/a
 
      29th Jan 2004
my Access database has 5 forms and 5 tables(SS# is PK
on all). Form1 has recordsource of an inner join sql and
updates 2 tables. I need form1 to update all 5 tables
with the SS#, so that i can use forms2-5 to update more
info on other tables on the same SS#. I have tried
putting a cmdSave button/event in vba to execute a INSERT
INTO command. (see code below)
I need someone to debug this code and to tell me if i
used the correct sql syntax and if i needed to use
adoConn or recordset objects or not.

Thanking You,

James Hartrich

Campus Info:
SS#, 1_20 Expiration, Work Location, Year of Study,
Academic Recognition, Academic Recognition 2, Academic
Recognition 3, Family Friend, Conversation Partner,
Current Campus Address, Family Text, Conversation Text,
Visa Type


Public Sub sql_insert_into_Campus_Info_Table()

Dim id_buf As String, p_buf As String, co_buf As String,
lab_buf As String, date_buf As String
Dim sqlStr As String, adoCon As ADODB.Connection, adoCon1
As ADODB.Connection, conString As String
Dim msg As String, rs As ADODB.Recordset, rs1 As
ADODB.Recordset, tst As Boolean, co_variant As Variant

On Error Resume Next

'set up the connection string
'conString = "Provider=MSDASQL"
conString = "Provider=Microsoft.Jet.OLEDB.4.0;"
conString = conString & "Data Source="
conString = conString & "C:\Documents and Settings\James
Hartrich\Desktop\international access db\Copy of JSH BETA
6 International_Program.mdb;"

'create the Connection object
Set adoCon = New ADODB.Connection
adoCon.ConnectionString = conString

'open the connection
adoCon.Open

'test for error
If Err <> 0 Then
msg = "an error occured trying to connect to the
International database:" & vbCrLf
msg = msg & "Error number: " & Err & vbCrLf
msg = msg & "Description: " & Err.Description
MsgBox msg
End If
Err.Clear

id_buf = Forms![AppDocs-T]![SS#]
'p_buf = Forms!clock_out!password
'co_buf = Forms!clock_out!clock_out
'lab_buf = Forms!clock_out!lab_id
'date_buf = Forms!clock_out!Date

'SQL query to find user and password in the db*****
MsgBox (id_buf)
'adoCon.BeginTrans

adoCon.Execute ("INSERT INTO [Campus Info] ([Campus Info].
[SS#], [Campus Info].[Work Location]) VALUES(id_buf,
NULL")
MsgBox (id_buf)

'if error, display message then quit
If Errn <> 0 Then
msg = "An error occurred trying to INSERT INTO the
Campus Info TABLE:" & vbCrLf
msg = msg & "Error number: " & Err & vbCrLf
msg = msg & "Description: " & Err.Description
MsgBox msg
'Set rs = Nothing
adoCon.Close
Exit Sub
End If
'adoCon.CommitTrans


adoCon.Close

End Sub
 
Reply With Quote
 
 
 
 
Rick Allison
Guest
Posts: n/a
 
      30th Jan 2004
James,

Boy oh boy. My guess is that you do not have a normalized database and
that's the root of the problem.

SS# is not good key and since you have it in so many tables as the PK start
there.

Sorry I can't help much more than that.

Rick


"James Hartrich" <(E-Mail Removed)> wrote in message
news:707901c3e6a3$f4a2e600$(E-Mail Removed)...
> my Access database has 5 forms and 5 tables(SS# is PK
> on all). Form1 has recordsource of an inner join sql and
> updates 2 tables. I need form1 to update all 5 tables
> with the SS#, so that i can use forms2-5 to update more
> info on other tables on the same SS#. I have tried
> putting a cmdSave button/event in vba to execute a INSERT
> INTO command. (see code below)
> I need someone to debug this code and to tell me if i
> used the correct sql syntax and if i needed to use
> adoConn or recordset objects or not.
>
> Thanking You,
>
> James Hartrich
>
> Campus Info:
> SS#, 1_20 Expiration, Work Location, Year of Study,
> Academic Recognition, Academic Recognition 2, Academic
> Recognition 3, Family Friend, Conversation Partner,
> Current Campus Address, Family Text, Conversation Text,
> Visa Type
>
>
> Public Sub sql_insert_into_Campus_Info_Table()
>
> Dim id_buf As String, p_buf As String, co_buf As String,
> lab_buf As String, date_buf As String
> Dim sqlStr As String, adoCon As ADODB.Connection, adoCon1
> As ADODB.Connection, conString As String
> Dim msg As String, rs As ADODB.Recordset, rs1 As
> ADODB.Recordset, tst As Boolean, co_variant As Variant
>
> On Error Resume Next
>
> 'set up the connection string
> 'conString = "Provider=MSDASQL"
> conString = "Provider=Microsoft.Jet.OLEDB.4.0;"
> conString = conString & "Data Source="
> conString = conString & "C:\Documents and Settings\James
> Hartrich\Desktop\international access db\Copy of JSH BETA
> 6 International_Program.mdb;"
>
> 'create the Connection object
> Set adoCon = New ADODB.Connection
> adoCon.ConnectionString = conString
>
> 'open the connection
> adoCon.Open
>
> 'test for error
> If Err <> 0 Then
> msg = "an error occured trying to connect to the
> International database:" & vbCrLf
> msg = msg & "Error number: " & Err & vbCrLf
> msg = msg & "Description: " & Err.Description
> MsgBox msg
> End If
> Err.Clear
>
> id_buf = Forms![AppDocs-T]![SS#]
> 'p_buf = Forms!clock_out!password
> 'co_buf = Forms!clock_out!clock_out
> 'lab_buf = Forms!clock_out!lab_id
> 'date_buf = Forms!clock_out!Date
>
> 'SQL query to find user and password in the db*****
> MsgBox (id_buf)
> 'adoCon.BeginTrans
>
> adoCon.Execute ("INSERT INTO [Campus Info] ([Campus Info].
> [SS#], [Campus Info].[Work Location]) VALUES(id_buf,
> NULL")
> MsgBox (id_buf)
>
> 'if error, display message then quit
> If Errn <> 0 Then
> msg = "An error occurred trying to INSERT INTO the
> Campus Info TABLE:" & vbCrLf
> msg = msg & "Error number: " & Err & vbCrLf
> msg = msg & "Description: " & Err.Description
> MsgBox msg
> 'Set rs = Nothing
> adoCon.Close
> Exit Sub
> End If
> 'adoCon.CommitTrans
>
>
> adoCon.Close
>
> End Sub



 
Reply With Quote
 
CSmith
Guest
Posts: n/a
 
      30th Jan 2004
Hi,

A few things are standing out at me right away...

1. Your SQL is not passing the value of your id_buf variable in your SQL
string. It should be "INSERT INTO...VALUES(' " & id_buf & " ', (rest of your
SQL here)..."

2. Eliminate the ";" at the end of your path string - example:
"...Program.mdb" not "...Program.mdb;"

3. If you're set on using ADO for this (which is fine), then you need to
execute your action query SQL statement using an ADODB.Command object.

>>> Form1 has recordsource of an inner join sql and updates 2 tables. <<<


If all of these tables have a 1-1 relationship on the SS#, then you should
combine them all into one flat table.

--
Calvin Smith
http://www.CalvinSmithSoftware.com - Automation Code
http://www.SpanglesNY.com - Fendi, Prada, etc - 60% off


"James Hartrich" <(E-Mail Removed)> wrote in message
news:707901c3e6a3$f4a2e600$(E-Mail Removed)...
> my Access database has 5 forms and 5 tables(SS# is PK
> on all). Form1 has recordsource of an inner join sql and
> updates 2 tables. I need form1 to update all 5 tables
> with the SS#, so that i can use forms2-5 to update more
> info on other tables on the same SS#. I have tried
> putting a cmdSave button/event in vba to execute a INSERT
> INTO command. (see code below)
> I need someone to debug this code and to tell me if i
> used the correct sql syntax and if i needed to use
> adoConn or recordset objects or not.
>
> Thanking You,
>
> James Hartrich
>
> Campus Info:
> SS#, 1_20 Expiration, Work Location, Year of Study,
> Academic Recognition, Academic Recognition 2, Academic
> Recognition 3, Family Friend, Conversation Partner,
> Current Campus Address, Family Text, Conversation Text,
> Visa Type
>
>
> Public Sub sql_insert_into_Campus_Info_Table()
>
> Dim id_buf As String, p_buf As String, co_buf As String,
> lab_buf As String, date_buf As String
> Dim sqlStr As String, adoCon As ADODB.Connection, adoCon1
> As ADODB.Connection, conString As String
> Dim msg As String, rs As ADODB.Recordset, rs1 As
> ADODB.Recordset, tst As Boolean, co_variant As Variant
>
> On Error Resume Next
>
> 'set up the connection string
> 'conString = "Provider=MSDASQL"
> conString = "Provider=Microsoft.Jet.OLEDB.4.0;"
> conString = conString & "Data Source="
> conString = conString & "C:\Documents and Settings\James
> Hartrich\Desktop\international access db\Copy of JSH BETA
> 6 International_Program.mdb;"
>
> 'create the Connection object
> Set adoCon = New ADODB.Connection
> adoCon.ConnectionString = conString
>
> 'open the connection
> adoCon.Open
>
> 'test for error
> If Err <> 0 Then
> msg = "an error occured trying to connect to the
> International database:" & vbCrLf
> msg = msg & "Error number: " & Err & vbCrLf
> msg = msg & "Description: " & Err.Description
> MsgBox msg
> End If
> Err.Clear
>
> id_buf = Forms![AppDocs-T]![SS#]
> 'p_buf = Forms!clock_out!password
> 'co_buf = Forms!clock_out!clock_out
> 'lab_buf = Forms!clock_out!lab_id
> 'date_buf = Forms!clock_out!Date
>
> 'SQL query to find user and password in the db*****
> MsgBox (id_buf)
> 'adoCon.BeginTrans
>
> adoCon.Execute ("INSERT INTO [Campus Info] ([Campus Info].
> [SS#], [Campus Info].[Work Location]) VALUES(id_buf,
> NULL")
> MsgBox (id_buf)
>
> 'if error, display message then quit
> If Errn <> 0 Then
> msg = "An error occurred trying to INSERT INTO the
> Campus Info TABLE:" & vbCrLf
> msg = msg & "Error number: " & Err & vbCrLf
> msg = msg & "Description: " & Err.Description
> MsgBox msg
> 'Set rs = Nothing
> adoCon.Close
> Exit Sub
> End If
> 'adoCon.CommitTrans
>
>
> adoCon.Close
>
> End Sub



 
Reply With Quote
 
 
 
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How do i insert reference to multiple tables without repeating Suzanne S. Barnhill Microsoft Word Document Management 0 11th Jul 2009 03:41 PM
VB 2005 Insert records into multiple tables AnikSol Microsoft ADO .NET 4 3rd Nov 2006 09:58 AM
How to insert into multiple tables with one update. Geir Holme Microsoft ADO .NET 1 11th Apr 2005 04:04 PM
Can I insert multiple tables of contents in word? =?Utf-8?B?bWV5ZXJzem9v?= Microsoft Word Document Management 3 10th Mar 2005 01:29 AM
Re: insert into multiple tables Sahil Malik Microsoft ADO .NET 0 7th Mar 2005 08:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:44 PM.