ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB Code works in 2000, but not 2003 (https://www.excelbanter.com/excel-programming/364859-vbulletin-code-works-2000-but-not-2003-a.html)

[email protected]

VB Code works in 2000, but not 2003
 
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


Rick S.

VB Code works in 2000, but not 2003
 
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?
--
Thanks


" wrote:

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



Kaak[_62_]

VB Code works in 2000, but not 2003
 

You can use:

application.DisplayAlerts = False

before closing the file

and reset by:

application.DisplayAlerts = True

with regards....

Jeroen


--
Kaak
------------------------------------------------------------------------
Kaak's Profile: http://www.excelforum.com/member.php...fo&userid=7513
View this thread: http://www.excelforum.com/showthread...hreadid=553716



All times are GMT +1. The time now is 01:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com