Use VB to add titles to Word Doc

J

jshumaker

I'm creating a word document from data in an Access 2000
database. Within the word template I have inserted a 3-
column table which contains a listing of items for a
particular customer order. I would like to add a title
to column 2: "Job No." & Column 3: "Serial No". Field
layout is follows:

[Model] [PartNo] [Serial No]

However, sometimes depending on the Model there may not be
a Part No. only a Serial No. And therefore would only need
to show two columns: Model and Serial No.

Any suggestions on how I would use VB to code the column
titles depending on if PartNo is not null? Thanks in
advance.

Here's my code for the Word doc bookmark:

strSQL = "SELECT Order.OrderID, Order.OrderDesc,
Order.OrderModules, " & _
"tblMachine.MachDesc, MachPartNo.PartNo,
MachPartNo.SerialNo, " & _
"MachPartNo.Descrip, MachPartNo.Model " & _
"FROM [tblMachine] INNER JOIN ([Order] LEFT
JOIN [MachPartNo] " & _
"ON Order.OrderID = MachPartNo_OrderID) ON
tblMachine.MachOrderID = Order.OrderDesc " & _
"WHERE Order.OrderID= " & Me![OrderID]
rst.Open strSQL

With rst
doc.Bookmarks("bmkMachDetailD").Select
Do Until .EOF
strMachModelD = Nz(.Fields("Model")) & " " & Nz
(.Fields("Descrip"))
strMachJobNo = Nz(.Fields("PartNo"))
strSerialNoD = Nz(.Fields("SerialNo"))
With objWord.Selection
.TypeText strMachModelD
.MoveRight wdCell
.TypeText strMachJobNo
.MoveRight wdCell
.TypeText strSerialNoD
.MoveRight wdCell
End With
.MoveNext
Loop
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top