var
  i : integer;
  j : integer;
  EParam : OleVariant;
  DocuType : OleVariant;
  IMEIEW : _WorkBook;
  IMEIES : _worksheet;
  dates : string;
  name:string;
1/    with adoquery1 do
2/    begin
3/      next;
4/      while not eof do
5/      begin
6/        for j:=0 to adoquery2.FieldCount-1 do
7/        begin
8/          name:=adoquery2.fields.Fields[j].FieldName;
9/          IMEIES.Cells.Item[i+2,j+1]:=adoquery2.fields.Fields[j].AsString;
10/        end;
11/        next;
12/        i:=i+1;
13/      end;
14/    end;单独执行第7或8可以进行,可是一并执行则到8时会出错。请教原因,谢谢!

解决方案 »

  1.   

    你是想把数据导到Excel中吧?你虽然定义了Excel的对象,可是并没有创建。当然你在附值的时候就会出现错误了。
      

  2.   

    IMEIES.Cells.Item[i+2,j+1]:=adoquery2.fields.Fields[j].AsString这句话你改成:IMEIES.Cells[i+2,j+1]:=adoquery2.fields.Fields[j].AsString
      

  3.   

    我有试过,也会出错的。不知道
    8/          name:=adoquery2.fields.Fields[j].FieldName;
    9/          IMEIES.Cells.Item[i+2,j+1]:=adoquery2.fields.Fields[j].AsString;
    有什么冲突?
      

  4.   

    Project MFRQuery1.exe raised exception class EAccessViolation with message 'Access violation at address 004B6782 in module 'MFRQuery1.exe'. Read of address 00000030',Process stopped. Use Step or Run to continue.