Well, I would strongly advise not using a SQL key word as a field name, but
having added the field to both tables, and deleted and recreated the link to
the SQL Server table (the new field wasn't visible in the linked table until
I did that) the only modification I had to make to the example I posted
earlier was to add the square brackets around the reference to the SQL
Server field in the SQL string as follows ...
Public Sub Append2SQL()
Dim strSQL As String
strSQL = "INSERT INTO dbo_authors ( au_id, au_lname, au_fname, " & _
"phone, address, city, state, zip, contract, [Group] ) SELECT " & _
"tblAuthors.au_id, tblAuthors.au_lname, tblAuthors.au_fname, " & _
"tblAuthors.phone, tblAuthors.address, tblAuthors.city, " & _
"tblAuthors.state, tblAuthors.zip, tblAuthors.contract,
tblAuthors.Group FROM tblAuthors;"
CurrentDb.Execute strSQL, dbFailOnError
End Sub
--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com
The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
Andre said:
Thanks Brendan,
I'm able to load the table now using very similar code. The only issue I'm
having is because of a column named "Group" in both the local and sql table.
I've tried enclosing it in [] but that doesn't help. Any ideas what I can
do?
Andre
"Brendan Reynolds" <brenreyn at indigo dot ie> wrote in message
The following works for me where "dbo_authors" is an ODBC-linked SQL
Server
table and "tblAuthors" is a local Jet table. I'm using Access 2003,
but
I
don't believe that should make any difference to this particular
operation.
Public Sub Append2SQL()
Dim strSQL As String
strSQL = "INSERT INTO dbo_authors ( au_id, au_lname, au_fname, " & _
"phone, address, city, state, zip, contract ) SELECT " & _
"tblAuthors.au_id, tblAuthors.au_lname, tblAuthors.au_fname, "
&
_
"tblAuthors.phone, tblAuthors.address, tblAuthors.city, " & _
"tblAuthors.state, tblAuthors.zip, tblAuthors.contract FROM
tblAuthors;"
CurrentDb.Execute strSQL, dbFailOnError
End Sub
--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com
The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
Brendan,
I was able to connect using a DSN, but not DSNLess. That's fine, not
optimal, but it will work. May I ask you what the syntax would be if
I'm
wanting to load a local Access table to a linked SQL table? I've tried
this
but it didn't like it:
Dim rst As Recordset
Dim connect As String
connect = "ODBC;DSN=HCPHPA;"
Set wspace = DBEngine.Workspaces(0)
Set db = wspace.OpenDatabase("", False, True, connect)
CurrentDb.Execute ("Insert Into dbo_Enrollment Select * from
enrollment")
The error says: run-time error 3155: odbc--insert on a linked table
'dbo_Enrollment failed.
I can't find anything on that error in the KB. Interestingly
enough,
I
get
the same error when I try to append the local table to the linked table
in
a
query. I'm connected as sa to sql.
Thanks again, Andre
Hope this helps...
Andre, I answer a lot of questions. I can't remember the details of
them
all. I need to see enough of the text of previous posts in the thread
to
remind me of what the question was.
Here's your reply from this morning:
Access 97 pre-dates ADO (or, at least, the wide-spread
availability
and
use
of ADO) and has little if any built-in support for ADO. If you're
using
Access 97 you'll want to use DAO instead. The nearest equivalent
of
CurrentProject.Connection in DAO would be CurrentDb.
Here's my post from last night:
I finally got back to this project and have been trying to
implement
your
suggestion below, but I can't for the life of me find
CurrentProject
in
Access 97. I've poked around a bit and it seems like that might
be
an
Access 2000 thing. If that's the case, what is the equivalent
command
in
Access 97?
Oh, and you are correct about cn being an ADO connection.
Thanks again, Andre
What to do about it? Well, you could link the SQL Server table
via
ODBC,
then the SQL statement can be executed by
CurrentProject.Connection,
which
will be able to see both records. That's probably the best
solution
in
most
circumstances. Alternatively, you could open a recordset on the
local
Jet
table (using CurrentProject connection) and loop through it,
adding
each
record in turn to the SQL Server table through the 'cn'
connection
to
SQL
Server.