Message Box Question

Frank123

Registered User.
Local time
Today, 15:35
Joined
Jun 29, 2016
Messages
31
Hi,

I'm new too access VBA and this may be easy. I'm using Access 2010 and I have a form with a button that opens up a Word document using the code below. The code also has a message box that pops up on the form that asks the user if they want to save the prior document version before making changes to it. I would like to know if there is a way to have the message box pop up in the Word Document after it opens instead of on the form. Not sure if this can be done. Any help would be greatly appreciated.


Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim filepath As String
Dim lngValue As Long

Set wrdApp = CreateObject("Word.Application")
filepath = Me.Preface
Set wrdDoc = wrdApp.Documents.Open(filepath)

lngValue = MsgBox("Would you like to save the prior version before making any changes? Y/N", vbYesNo + vbQuestion, "Save Prior Version")

If lngValue = vbYes Then
wrdApp.ActiveDocument.SaveAs2 "\\jbxsw\Plans\Preface Prior Version.docx"
Else
End If

wrdApp.Visible = True

Set wrdApp = Nothing
 
Just guessing here, but try
Code:
lngValue = wrdApp.MsgBox("Would you like to save the prior version before making any changes? Y/N", vbYesNo + vbQuestion, "Save Prior Version")
 
Thank you for your quick reply. Unfortunately, it did not work. I got the following error message:

"The expression On Click you entered as an event property setting produced the following error: Method or data member not found."
 
Guessed wrong then, sorry. :(

I expected that code would use the MSGBOX function of the Word app.
A quick Google does not show anything that I can find.
 
Thanks for your help. I'll try to find way around it.
 
in order for you to accomplish this
you need to make your Document as
Macro Enabled Document (.docm)
and not .docx

Open your document and go to
VBE (Alt-F11).
click on ThisDocument on Project Window.
Paste the code on the VBE:

Code:
Private Sub Document_Open()
    If MsgBox("Do you want to save the prior version before making any changes?", vbQuestion + vbYesNo, "Save Document") = vbYes Then
        Me.SaveAs2 "\\jbxsw\Plans\Preface\Prior Version_" & Me.Name
    End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom