Whohoo! I got it to work and it's quite spiff! Peter Huang on one of the
MSDN boards showed me the error of my ways. The reason I wasn't getting
any event action was because I declared the class object within the
function instead of as a module-level variable. This should have been
obvious, but, hey, sometimes you just can't see the forest for all those
dang trees!
To get the message box to be visible I had to minimize Word for a
moment. In any case, my users can now look at, print preview, print,
etc. but they can't make changes.
Here's the glorious code:
Class Module-----------------------------------------
Option Compare Database
Option Explicit
Public WithEvents appWord As Word.Application
Public WithEvents docWord As Word.Document
Private Sub appWord_DocumentBeforeClose(ByVal Doc As Word.Document,
Cancel As Boolean)
docWord.Close False
appWord.Quit
End Sub
Public Sub appWord_DocumentBeforeSave(ByVal Doc As Word.Document,
SaveAsUI As Boolean, Cancel As Boolean)
appWord.WindowState = wdWindowStateMinimize
MsgBox "This record is locked. You cannot save this file.",
vbInformation + vbOKOnly, _
"Locked Record"
Cancel = True
appWord.WindowState = wdWindowStateNormal
End Sub
Public Sub OpenNewDocument(strFileName As String)
Set docWord = appWord.Documents.Open(strFileName)
End Sub
Public Sub Class_Initialize()
Set appWord = New Word.Application
appWord.Visible = True
End Sub
----------------------------------------------------------
Code Module-----------------------------------------------
Dim myWord As clsMSWord
Public Function OpenFile()
On Error GoTo Err_OpenFile
Dim frm As Form
Dim bolWordOpen As Boolean
Dim strFile As String
Set frm = Screen.ActiveForm
If IsNull(frm![EventsSub].Form.oleLinked) Then
MsgBox "There is no file attached to this event.", vbOKOnly,
"Attachment Error"
Exit Function
End If
' Word files should be opened by Word so we can manipulate them
appropriately
If frm![EventsSub].Form!FileType = "doc" Then
' Check to see if the record is locked. Open the file
appropriately.
If frm![EventsSub].Form.Locked Then
' Open as class object so events can be controlled
Set myWord = New clsMSWord
' Opening the file errors if I pass it the file name without
assigning it to a variable
strFile = frm![EventsSub].Form.txtLinkFilePath
myWord.OpenNewDocument (strFile)
Else
' Otherwise let Access OLE open the attached file
frm![EventsSub].Form.oleLinked.Action = acOLEActivate
End If
Else
' Otherwise let Access OLE open the attached file
frm![EventsSub].Form.oleLinked.Action = acOLEActivate
End If
Exit Function
Err_OpenFile:
Call adcRunTimeErr(Err.Number, Err.Description, "OpenFile")
End Function
-----------------------------------------------------------
Hope this saves someone else some time!
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!