break on
; copy source table to target table if required ( recordcount )
$sourcedatabase = "m:\msaccess\db1.mdb"
$sourcetable = "table1"
$targetdatabase = "m:\msaccess\db2.mdb"
$targettable = "table1"
; get my objects
$access = olecreateobject ( "access.application" )
$docmd = val( "&" + olegetproperty ( $access, "docmd" ) )
$dbengine = val( "&" + olegetproperty ( $access, "dbengine" ) )
; get record count of source table
$database = val( "&" + olecallfunc ( $dbengine, "OpenDatabase", "s", "$sourcedatabase" ) )
$recordset = val ( "&" + olecallfunc ( $database, "openrecordset", "s",
"$sourcetable" ))
$sourcecount = val ( olegetproperty ( $recordset, "recordcount" ) )
?"Table $sourcetable in $sourcedatabase contains $sourcecount records"
$= olereleaseobject ( $recordset )
$= olereleaseobject ( $database )
; get record count of target table
$database = val( "&" + olecallfunc ( $dbengine, "opendatabase", "s",
"$targetdatabase" ) )
$recordset = val ( "&" + olecallfunc ( $database, "openrecordset", "s",
"$targettable" ))
$targetcount = val ( olegetproperty ( $recordset, "recordcount" ) )
?"Table $targettable in $targetdatabase contains $targetcount records"
$= olereleaseobject ( $recordset )
$= olereleaseobject ( $database )
; check record counts and copy as required
if $sourcecount > $targetcount
?"Copying tables ... "
$= olecallproc ( $access, "opencurrentdatabase", "s",
"$targetdatabase")
$= olecallproc ( $docmd, "deleteobject", "ss",
"0",
"$targettable" )
$= olecallproc ( $docmd, "transferdatabase", "ssssss",
"0",
"microsoft access",
"$sourcedatabase",
"0",
"$sourcetable",
"$targettable" )
$= olecallproc ( $access, "closecurrentdatabase")
else
?"No need to copy"
endif
; release my objects ( very important )
$= olereleaseobject ( $dbengine )
$= olereleaseobject ( $docmd )
$= olecallproc ( $access, "Quit" )
$= olereleaseobject ( $access )
exit