I have the following code, that allows a user to upload a user specified file. Before uploading, a unique number is generated. I need to print that unique identifier onto a label as a barcode. I have created a Word application that creates a new document. Then it creates another new document with the label format that I need to be able to print to. I need to select the cell at Row 1 Column 1 and put the first number from my barcode() array, I then need to move to row 2 column 1. There are only 20 labels in a column so when I reach 20 I check to see if I'm in the last usable column (7). If I am, I need to create another page of labels (still unknown how to accomplish that!). If I'm not in column 7, then add 2 to the column, reset the row back to 1 and continue filling in the table. Unfortunately, I keep getting error messages that Tables is not a method. I have tried calling it from my Word application variant and the document variant, but it just won't work! I have copied extensive examples from the help and still no love!! If there is anyone out there with OLE VBA knowledge, I beg you to share with me!! Thanks for any assistance!
(I previously was asking about doing this procedure with Delphi - but was completely lost! So I switched to Word - Thanks again for any help).
Leslie
procedure TfrmMainMenu.UploadVenire1Click(Sender: TObject);
var
F: TextFile;
S: string;
FullName, LastName: string;
j, i, k, JurNum: integer;
barcode: array[1..350] of integer;
Word, wrdDoc, wrdSelection, myCell, wrdTable: Variant;
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(F, OpenDialog1.FileName); { File selected in dialog }
Reset(F);
qryMaxJuror.Active := True;
JurNum := qryMaxJuror.FieldByName('JURNUM').AsInteger;
{JurNum := JurNum + 1;}
JurNum := 1;
for j := 1 to 350 do
begin
Readln(F, S); { Read first line of file }
FullName := Copy(S, 160,30); // extract name
i := Pos( ',', FullName);
qryVenireUpdate.ParamByName('LASTNAME').AsString := Copy(FullName,0,i-1);
qryVenireUpdate.ParamByName('FIRSTNAME').AsString := Copy(FullName, (i+2), (30 - Length(LastName)));
qryVenireUpdate.ParamByName('ADDRESS').AsString := copy(S,190,25); // extract address
qryVenireUpdate.ParamByName('CITY').AsString := copy(S,215,15); //extract city
qryVenireUpdate.ParamByName('STATE').AsString := copy(S,230,2);
qryVenireUpdate.ParamByName('ZIPCODE').AsString := copy(S,232,9);
qryVenireUpdate.ParamByName('SSN').AsString := copy(S,151,9);
qryVenireUpdate.ParamByName('TERMDATE').AsInteger := StrToInt ('20' + (copy(S,16,6)));
qryVenireUpdate.ParamByName('ORGPOST').AsInteger := StrToInt('20' + (copy(S,16,6)));
qryVenireUpdate.ParamByName('JURNUM').AsInteger := JurNum;
qryVenireUpdate.ParamByName('STATUSCD').AsString := 'NR';
qryVenireUpdate.ParamByName('UPDATE').AsString := 'F';
qryVenireUpdate.ParamByName('PUBEMP').AsString := 'F';
qryVenireUpdate.ExecSQL;
barcode[j] := JurNum;
JurNum := JurNum + 1;
end;
CloseFile(F);
Word := CreateOleObject('Word.Application');
Word.Documents.Add();
Word.Visible := True;
wrdDoc := Word.MailingLabel.CreateNewDocument (Name:='5167');
wrdDoc.Activate;
wrdTable := wrdDoc.Tables(1);
j := 1;
i := 1;
k := 1;
for j := 1 to 350 do
begin
for i := 1 to 20 do
begin
myCell := wrdTable.Cell(Row:=i, Column:= k);
myCell.Font.Name := 'Code 39';
myCell.Font.Size := 14;
myCell.Value := barcode[j];
end;
if i = 20 then
begin
if k = 7 then
begin
k := -1;
end;
i := 1;
k := k + 2;
end;
end;
end;
end;
(I previously was asking about doing this procedure with Delphi - but was completely lost! So I switched to Word - Thanks again for any help).
Leslie
procedure TfrmMainMenu.UploadVenire1Click(Sender: TObject);
var
F: TextFile;
S: string;
FullName, LastName: string;
j, i, k, JurNum: integer;
barcode: array[1..350] of integer;
Word, wrdDoc, wrdSelection, myCell, wrdTable: Variant;
begin
if OpenDialog1.Execute then { Display Open dialog box }
begin
AssignFile(F, OpenDialog1.FileName); { File selected in dialog }
Reset(F);
qryMaxJuror.Active := True;
JurNum := qryMaxJuror.FieldByName('JURNUM').AsInteger;
{JurNum := JurNum + 1;}
JurNum := 1;
for j := 1 to 350 do
begin
Readln(F, S); { Read first line of file }
FullName := Copy(S, 160,30); // extract name
i := Pos( ',', FullName);
qryVenireUpdate.ParamByName('LASTNAME').AsString := Copy(FullName,0,i-1);
qryVenireUpdate.ParamByName('FIRSTNAME').AsString := Copy(FullName, (i+2), (30 - Length(LastName)));
qryVenireUpdate.ParamByName('ADDRESS').AsString := copy(S,190,25); // extract address
qryVenireUpdate.ParamByName('CITY').AsString := copy(S,215,15); //extract city
qryVenireUpdate.ParamByName('STATE').AsString := copy(S,230,2);
qryVenireUpdate.ParamByName('ZIPCODE').AsString := copy(S,232,9);
qryVenireUpdate.ParamByName('SSN').AsString := copy(S,151,9);
qryVenireUpdate.ParamByName('TERMDATE').AsInteger := StrToInt ('20' + (copy(S,16,6)));
qryVenireUpdate.ParamByName('ORGPOST').AsInteger := StrToInt('20' + (copy(S,16,6)));
qryVenireUpdate.ParamByName('JURNUM').AsInteger := JurNum;
qryVenireUpdate.ParamByName('STATUSCD').AsString := 'NR';
qryVenireUpdate.ParamByName('UPDATE').AsString := 'F';
qryVenireUpdate.ParamByName('PUBEMP').AsString := 'F';
qryVenireUpdate.ExecSQL;
barcode[j] := JurNum;
JurNum := JurNum + 1;
end;
CloseFile(F);
Word := CreateOleObject('Word.Application');
Word.Documents.Add();
Word.Visible := True;
wrdDoc := Word.MailingLabel.CreateNewDocument (Name:='5167');
wrdDoc.Activate;
wrdTable := wrdDoc.Tables(1);
j := 1;
i := 1;
k := 1;
for j := 1 to 350 do
begin
for i := 1 to 20 do
begin
myCell := wrdTable.Cell(Row:=i, Column:= k);
myCell.Font.Name := 'Code 39';
myCell.Font.Size := 14;
myCell.Value := barcode[j];
end;
if i = 20 then
begin
if k = 7 then
begin
k := -1;
end;
i := 1;
k := k + 2;
end;
end;
end;
end;