vba - Opening a table from another mdb file with ADO in MSAccess -
i'm trying access table mdb file. isn't linked table can fix, please don't suggest it.
edit: part of archive tool creates backup file of backend of database date range, , deletes data. before delete data, suggested check , make sure data copied on created backup. (ie, if worst case scenario happened , share folder lost connection or something, , not data copied over, access database deleted data anyway)
if there's way create linked table in access , delete link in end vba, not manually, maybe work(?) hoping way wouldn't cause database bloat as has been in past.
i'm trying check if data copied on backup file before delete ones in current database.
dim rs adodb.recordset rs.connectionstring = "driver={microsoft access driver (*.mdb)};" & _ "dbq=backup.mdb;defaultdir=c:\fish;"
i'm having trouble here syntax. know works currentdb, if table in different mdb file? tried defaultdir=c:\fish , defaultdir=c:\fish\ there i'm missing or lot more complicated should attempt?
the rest of think understand how fieldvalues compare, trying connect table in different mdb file giving me trouble.
first of all: gord said in comment, can't see reason against using linked table either.
but in end doesn't matter if create linked table , open local recordset
on it, or if open recordset
directly on table in other access database.
so i'll show solutions both ways:
1. approach question
your connection string works me, there mistakes in rest of code:
- an
adodb.recordset
doesn't have propertyconnectionstring
...it's calledactiveconnection
instead. - you need create new
adodb.recordset
before try set connection string or open recordset
the following code works me:
dim rs adodb.recordset set rs = new adodb.recordset rs.activeconnection = "driver={microsoft access driver (*.mdb)};" & _ "dbq=backup.mdb;defaultdir=c:\fish;" rs.open "select * foo"
2. using linked table
create it:
docmd.transferdatabase aclink, "odbc", ";database=c:\fish\backup.mdb", actable, "tablename", "tablenamelocal", false
note: tablename
original name of source table, , tablenamelocal
name linked table have in local database. (you can use same names if want, of course)
delete it:
docmd.deleteobject actable, "tablenamelocal"
Comments
Post a Comment