Adding an Access field via ADOCommand issues

From: jason (jason_at_no-replies.com)
Date: 12/02/03

  • Next message: Willy Verbiest: "Re: TADOQuery getting in dsEdit after closing Entry form"
    Date: 1 Dec 2003 21:40:02 -0700
    
    

    Hi guys,
    SOrry for my last post, accidentally hit enter!

    Anyway, I am using and ADOCommand at runtime to create a new field/column in an MS Access database table.

    Here's a snippet of my code...
    var
      TableFields, SQLCommands : TStringList;
    .....
    // Check Set Up table fields
    DataMod.ADOCon.GetFieldNames('Setup', TableFields);

    if not (TableFields.Find('NextStatDate', FieldIndex)) then
      SQLCommands.Add('ALTER TABLE Setup ADD COLUMN NextStatDate TEXT(8)');

    DataMod.tblSetUp.Close;

    for FieldIndex := 0 to SQLCommands.Count - 1 do
    begin
      if SQLCommands.Strings[FieldIndex] <> '' then
      begin
         DataMod.ADOCommand.CommandType := cmdText;
         DataMod.ADOCommand.CommandText := SQLCommands.Strings[FieldIndex];
         DataMod.ADOCommand.Execute;
      end;
    end;

    This code runs fine. I check the database table with Access and can see that the field/column has been created. However, when I try and assign a value to the field....

              DataMod.tblSetUp.FieldByName('NextStatDate').AsString := DateToStr( now );

    I get the following error..
    EDataBaseError with message 'tblSetUp: Field 'NextStatDate' not found'.

    Any pointers??
    Thanks,
    Jason


  • Next message: Willy Verbiest: "Re: TADOQuery getting in dsEdit after closing Entry form"