Yes. You can specify the database password in the IN clause of an INSERT
SQL statement in Microsoft Access. If you would rather avoid writing the
VBA involved in using the DAO or ADO methods and just run your SQL statement
directly from the query window, then create a new query and copy/paste the
following SQL statement into the SQL View pane (substitute your own password
for myPassword):
INSERT INTO my_table IN '' [;DATABASE=C:\DB1.mdb;PWD=myPassword] SELECT *
FROM my_table;
... then execute your query.
Note that Access will translate this into Jet SQL when you save it, so the
saved query will use the following syntax, which doesn't include the IN
clause:
INSERT INTO [;DATABASE=C:\DB1.mdb;PWD=mypassword].my_table
SELECT *
FROM my_table;
Of course, your database password will be visible in the destination
connection string property of your query for everyone to read, so this isn't
a very secure way to do it. In your case, it sounds like both databases
have the same password. If this is correct, then those who can get into the
first database already know the password for the second database, so this
doesn't pose an issue.
But for others who might use this method under typical conditions, I
recommend that they write VBA code for the query in a module using the DAO
or ADO methods instead, and then compile the database into an MDE file so
that the source code, including the database password for the remote
database, is hidden from view. And the original MDB file should be kept
available so that changes can be made in the future and recompiled into a
new MDE as the need arises.
HTH.
Gunny
See
www.QBuilt.com for all your database needs.
See
www.Access.QBuilt.com for Microsoft Access tips.
Brendan Reynolds said:
I can't find anything in the help file, the KB or the MSDN library about
specifying a database password using the IN clause, so unless someone else
knows differently, it would appear that it can't be done. You can, of
course, link the table, or use DAO or ADO. See the following KB
article
for
the DAO method ...
http://support.microsoft.com/default.aspx?scid=kb;en-us;209953
... and this KB article for the ADO method ...
http://support.microsoft.com/default.aspx?scid=kb;en-us;191754
--
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.
Hi
I have 2 databases and both of them have identical table (i.e., same
structure) and also both are PASSWORD PROTECTED.
I have to insert records from one table (database #1) to another table
(database #2)
i tried the following SQL
insert into my_table in 'C:\DB1.mdb' select * from my_table
i'm getting an error "NOT A VALID PASSWORD". Is there any way in
which
i
can specify the password in the insert statement.
Warm Regards