Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why 'Unprotect' works for 2003 but not 2000?! OrientalPearl Excel Programming 13 April 3rd 06 01:44 AM
Excel 2000 Code works except in debug mode Bob Smedley Excel Programming 0 January 24th 06 01:21 AM
VBA Code works in Excel 2003 but won't work in Excel 2000 aglazer Excel Programming 2 September 5th 05 03:52 PM
VBA Code works in Excel 2003 but won't work in Excel 2000 [email protected] Excel Programming 0 September 5th 05 09:05 AM
VBA Code works in 2000 not 97 Michael Beckinsale Excel Programming 1 January 20th 04 05:38 PM


All times are GMT +1. The time now is 07:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"