Ashfaque
Search Beautiful Girls from your town for night
- Local time
- Today, 09:45
- Joined
- Sep 6, 2004
- Messages
- 897
Hi,
I have below vba code in a sub that opens word application and generates the data from a table based on criteria provided thru a form.
These lines are smoothly working..
But I need to place some headings in first line or second line of the document and then to start the table information to appear in the doc.
I tried to place my company name below way (see bold lines);
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim I As Integer
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT * FROM T_CustomerMaster WHERE SALESMANCODE='" & Forms!F_ReportMaster!TxtRepCode & "' order by custcode;")
WordSetup
doc.Tables.Add Range:=doc.Range, numrows:=1, numcolumns:=5
'Trying to place main heading
'doc.Range(1, 0).Text = "fsdafds"
'doc.Tables(1).Columns(0).Cells(0).Range.Text = "My Company Name"
doc.Tables(1).Columns(1).Cells(1).Range.Text = "CODE"
doc.Tables(1).Columns(2).Cells(1).Range.Text = "CUST NAME"
doc.Tables(1).Columns(3).Cells(1).Range.Text = "REP"
doc.Tables(1).Columns(4).Cells(1).Range.Text = "CR. LIMIT"
doc.Tables(1).Columns(5).Cells(1).Range.Text = "CR. PERIOD"
I = 1
Do Until rs.EOF
doc.Tables(1).Columns(1).Cells.Add
doc.Tables(1).Columns(1).Cells(I + 1).Range.Text = rs.Fields(0)
doc.Tables(1).Columns(2).Cells(I + 1).Range.Text = rs.Fields(1)
doc.Tables(1).Columns(3).Cells(I + 1).Range.Text = rs.Fields(2)
doc.Tables(1).Columns(4).Cells(I + 1).Range.Text = rs.Fields(16)
doc.Tables(1).Columns(5).Cells(I + 1).Range.Text = rs.Fields(17)
doc.Tables(1).Columns.AutoFit
I = I + 1
rs.MoveNext
Loop
doc.Activate
......
.......
But the table starting from column 1 and cell 1 till data ends up.
Finally I converted my trial lines to remark as it is not working at all.
Can someone please help?
Thanks,
Ashfaque
I have below vba code in a sub that opens word application and generates the data from a table based on criteria provided thru a form.
These lines are smoothly working..
But I need to place some headings in first line or second line of the document and then to start the table information to appear in the doc.
I tried to place my company name below way (see bold lines);
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim I As Integer
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT * FROM T_CustomerMaster WHERE SALESMANCODE='" & Forms!F_ReportMaster!TxtRepCode & "' order by custcode;")
WordSetup
doc.Tables.Add Range:=doc.Range, numrows:=1, numcolumns:=5
'Trying to place main heading
'doc.Range(1, 0).Text = "fsdafds"
'doc.Tables(1).Columns(0).Cells(0).Range.Text = "My Company Name"
doc.Tables(1).Columns(1).Cells(1).Range.Text = "CODE"
doc.Tables(1).Columns(2).Cells(1).Range.Text = "CUST NAME"
doc.Tables(1).Columns(3).Cells(1).Range.Text = "REP"
doc.Tables(1).Columns(4).Cells(1).Range.Text = "CR. LIMIT"
doc.Tables(1).Columns(5).Cells(1).Range.Text = "CR. PERIOD"
I = 1
Do Until rs.EOF
doc.Tables(1).Columns(1).Cells.Add
doc.Tables(1).Columns(1).Cells(I + 1).Range.Text = rs.Fields(0)
doc.Tables(1).Columns(2).Cells(I + 1).Range.Text = rs.Fields(1)
doc.Tables(1).Columns(3).Cells(I + 1).Range.Text = rs.Fields(2)
doc.Tables(1).Columns(4).Cells(I + 1).Range.Text = rs.Fields(16)
doc.Tables(1).Columns(5).Cells(I + 1).Range.Text = rs.Fields(17)
doc.Tables(1).Columns.AutoFit
I = I + 1
rs.MoveNext
Loop
doc.Activate
......
.......
But the table starting from column 1 and cell 1 till data ends up.
Finally I converted my trial lines to remark as it is not working at all.
Can someone please help?
Thanks,
Ashfaque