VB Code works in 2000, but not 2003

M

mleviton

I am using an Access db to populate an excel and a word document, print
them, and then close. When it runs, the user should not be promted to
save changes when the documents close. The code includes
"objWord.Documents("timesheet.doc").Close SaveChanges = False" and
works on the win2000 server but the win2003 server prompts the user to
save changes. Here is a portion of the code:

objWord.Visible = True
objWord.Documents.Open ("F:\database\timesheet\timesheet.doc")
objWord.WindowState = wdWindowStateMaximize

rs.MoveFirst
'Insert Timesheet information
objWord.Selection.GoTo What:=wdGoToBookmark, Name:="bkmTDate"
Do While Not rs.EOF
objWord.Selection.Text = rs!TDate
objWord.Selection.MoveRight unit:=wdCell
objWord.Selection.Text = rs!DocketID
objWord.Selection.MoveRight unit:=wdCell
objWord.Selection.Text = rs!Time
objWord.Selection.MoveRight unit:=wdCell
If Not IsNull(rs!TCode1) Then
objWord.Selection.Text = rs!TCode1
Else
objWord.Selection.Text = "0"
End If
objWord.Selection.MoveRight unit:=wdCell
If Not IsNull(rs!TCode2) Then
objWord.Selection.Text = rs!TCode2
Else
objWord.Selection.Text = "0"
End If
objWord.Selection.MoveRight unit:=wdCell
If Not IsNull(rs!TCode3) Then
objWord.Selection.Text = rs!TCode3
Else
objWord.Selection.Text = "0"
End If
objWord.Selection.MoveRight unit:=wdCell
If Not IsNull(rs!TCode4) Then
objWord.Selection.Text = rs!TCode4
Else
objWord.Selection.Text = "0"
End If
'objWord.Selection.Goto What:=wdGoToBookmark,
Name:="bkmNotes"
objWord.Selection.MoveRight unit:=wdCell
If Not IsNull(rs!TText) Then objWord.Selection.Text =
rs!TText
objWord.Selection.MoveRight unit:=wdCell
rs.MoveNext
Loop

rs.Close
Set rs = Nothing

Set rs = New ADODB.Recordset
With rs
.ActiveConnection = CurrentProject.Connection
.CursorLocation = adUseServer
.CursorType = adOpenKeyset
.LockType = adLockOptimistic
.Open "SELECT * FROM tblTimesheetMaster WHERE
TimesheetMasterID = " & strMasterID & ";"
End With

rs.MoveFirst

If Not IsNull(rs!Comments) Then
objWord.Selection.GoTo What:=wdGoToBookmark,
Name:="bkmComment"
objWord.Selection.Text = rs!Comments
End If
objWord.Selection.GoTo What:=wdGoToBookmark,
Name:="bkmEmployee"
objWord.Selection.Text = rs!EmployeeName
objWord.Selection.GoTo What:=wdGoToBookmark,
Name:="bkmHours"
objWord.Selection.Text = rs!TotalHours
objWord.Selection.GoTo What:=wdGoToBookmark,
Name:="bkmStartDate"
objWord.Selection.Text = rs!PPBegin
objWord.Selection.GoTo What:=wdGoToBookmark,
Name:="bkmEndDate"
objWord.Selection.Text = rs!PPEnd
objWord.Selection.GoTo What:=wdGoToBookmark,
Name:="bkmEmpNo"
objWord.Selection.Text = rs!EmployeeID
objWord.Selection.HomeKey unit:=wdStory
If booAllPages Then
objWord.ActiveDocument.PrintOut
Else
objWord.ActiveDocument.PrintOut
Range:=wdPrintRangeOfPages, Pages:=strPages
End If
objWord.Documents("timesheet.doc").Close SaveChanges =
False
If Not booWordOpen Then
objWord.Quit
End If

Set objWord = Nothing
rs.Close
Set rs = Nothing
MergeIt = True
End If

End Sub

Any suggestions would be greatly appreciated. Thanks, PPT
 
G

Guest

Though I can't be of help to you, I'm trying to do something similar.
Specifically, I have a spreadsheet with an inventory code number in one
column and I want to populate about 8 other columns with information from an
Access database. Will the code portion shown in your question allow me to do
this? I've worked a fair amount with Excel VBA, but have no idea where to
begin calling information from a database based on a key from Excel. Does the
infomation come across row by row, or would it be dumped as a batch after all
of the "keys" are entered?
 
K

Kaak

You can use:

application.DisplayAlerts = False

before closing the file

and reset by:

application.DisplayAlerts = True

with regards....

Jeroen
 

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