
Using DAO to insert records
Hi Todd
As well as referring to collection members by index number, you can refer to
them by name. So your entire loop:
Quote:
> iCount := vDB.TableDefs.Count;
> For I := 0 To iCount - 1 Do
> Begin
> If UpperCase(vDB.TableDefs[I].Name) = UpperCase(FTableName) Then
> Begin
> vTable := vDB.TableDefs[I];
> bFoundIt := True;
> Break;
> End;
> End;
can be replaced by:
vTable := vDB.TableDefs(FTableName)
The best way to empty a table is by executing a SQL statement. I don't know
what your string concatenation operator is, but assuming it's "&" as in VB:
vDB.Execute 'Delete * from ' & FTableName
--
Good Luck!
Graham Mandeno [Access MVP]
Auckland, New Zealand
Return mail address is invalid in a vain attempt to reduce spam.
Please post new questions or followups to newsgroup.
Quote:
> Well, I got this far, but I am not sure if what I am doing is the best
> way to do it. For instance, I loop through all of the tables to get the
> one I want. Is there a better way to do this?
> I would like to empty the table. Is there an Empty method?
> procedure TExportToAccess.OpenAccessTable;
> var
> vAccessApp: Variant;
> vDB: Variant;
> vTable: Variant;
> vRecord: Variant;
> vFields: Variant;
> sEngine: String;
> sValue: String;
> iCount: Integer;
> I: Integer;
> bFoundIt: Boolean;
> begin
> bFoundIt := False;
> If IniRec.DAOVer = DAO35 Then
> sEngine := 'DAO.DBEngine.35'
> Else
> sEngine := 'DAO.DBEngine.36';
> Try
> vAccessApp := GetActiveOleObject(sEngine);
> Except
> vAccessApp := CreateOleObject(sEngine);
> End;
> vDB := vAccessApp.OpenDatabase(FDatabaseName);
> iCount := vDB.TableDefs.Count;
> For I := 0 To iCount - 1 Do
> Begin
> If UpperCase(vDB.TableDefs[I].Name) = UpperCase(FTableName) Then
> Begin
> vTable := vDB.TableDefs[I];
> bFoundIt := True;
> Break;
> End;
> End;
> If bFoundIt Then
> Begin
> vRecord := vTable.OpenRecordSet;
> vRecord.AddNew;
> vRecord.AcctNo := '123456';
> vRecord.Update;
> End;
> vDB.Close;
> vAccessApp := UnAssigned;
> end;
> Todd
> --
> Todd Cary
> Ariste Software
> 2200 D Street Extension
> Petaluma, CA 94952
> 707-773-4523
> [It is simplicity that makes the uneducated more effective than
> the educated when addressing popular audiences. - Aristotle]