Rad:

Errrrrmmm .... Ummmmmm .....

Here you go ...

code:

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


Here's the deal - I would have prefered not to open up a new recordset to get the record count. I don't know if this will effect your performance or not.

There is another method of getting the record count ( by querying the properties of the tabledef for table1 ), but unfortunately, since KiX OLE doesn't support olegetproperty parameters, one can't enumerate the tabledefs collection (Ruud - are you listening ?)

Shawn.

p.s.

I need to get me a KiX coding standard real bad - anyone want to offer up any suggestions or better yet - write a standard. I guess the trick will be for everyone to agree on it !

Shawn..

[This message has been edited by Shawn (edited 20 July 2000).]