I've just copied your code and run it under Visual Basic and it worked fine. So its not likely to be a problem with my Word installation or settings..
Here is the the complete code for one of the routines. $result is obtained from a call like
$result=mysql_query("select * from employee");
and $tempheader and $tempdate are two temporry filenames such as
c:\temp\tempheader.doc
C:\temp\tempdata.doc
function CreateWordTable($result, $tempheader, $tempdata)
{
$intNum_of_fields = mysql_num_fields($result); //Get the number offields
$intNum_of_rows = mysql_num_rows($result); //Get the number of rows
//Create the header document
$wordTable = new COM("word.application") or die("Unable to instantiate Word");
$wordTable->Visible=0;
$wordTable->Documents->Add();
//Create a temporary table in Word
$wordTable->ActiveDocument->Tables->Add($wordTable->Selection->Range,1,$intNum_of_fields);
for($intFieldCount=0; $intFieldCount < $intNum_of_fields; $intFieldCount++)
{
$columnName = mysql_field_name($result,$intFieldCount);
$wordTable->Selection->TypeText($columnName); //Write to the current cell
$wordTable->Selection->MoveRight(); //Tab to the next cell
}
//Save the temporary table Word file
$wordTable->ActiveDocument->SaveAs($tempheader);
//Closing word
$wordTable->Documents->Close();
//$wordTable->Quit();
//Free the object
//$wordTable->Release();
//$wordTable = null;
//Create the data document
//Open the word document that we will be using for a temporary table
//$wordTable = new COM("word.application") or die("Unable to instanciateWord");
$wordTable->Documents->Add();
//Create a temporary table in Word
$wordTable->ActiveDocument->Tables->Add($wordTable->Selection->Range,$intNum_of_rows,$intNum_of_fields);
$intRowCount = 0; //Initialization
//Start populating the table with data from the recordset
while($intRowCount < $intNum_of_rows)
{
$strResultArray = mysql_fetch_array($result);
for($columnCount=0; $columnCount < $intNum_of_fields ; $columnCount++)
{
$wordTable->Selection->TypeText("$strResultArray[$columnCount]"); //Write to the current cell
$wordTable->Selection->MoveRight(); //Tab to the next cell
}
$intRowCount++;
}
//Save the temporary table Word file
$wordTable->ActiveDocument->SaveAs($tempdata);
//Closing word
$wordTable->Documents->Close();
$wordTable->Quit();
//Free the object
$wordTable->Release();
$wordTable = null;
};