Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error handling: Document is locked for editing, MSAccess

Status
Not open for further replies.

cablass

Technical User
Jul 11, 2008
5
I have a mail merge procedure based on bookmarked templates. I have added an error routine:

On Error Goto cmdSendLetter_Click_Error

**Procedure**

Exit Sub

cmdSendLetter_Click_Error:

msgBox ("I'm sorry I have a headache right now" & Chr(13) _
"Please try again later, I may be feeling better")

End Sub


I have tried to run the procedure with a deliberate error: if I try to create another letter to the same client based on the same merged document, I get a msgBox that the document is locked for editing. My error routine is not bypassing this but jumping into debug. I'm sure I'm making a very basic (rookie!) error but would appreciate some advice.

Thanks in advance

Yvonne
 
Oops. Actually my error handler does prevent the user accessing the code. However a msgBox warning the user the document is locked still appears, how can I disable this & show my 'headache' msgbox first?
 
Perhaps you can use an If statement to get around it...

Something like: (in the error handler)
Code:
If Err.Number = #### Then '#### = actual error number
  msgBox ("I'm sorry I have a headache right now" & Chr(13) _
"Please try again later, I may be feeling better")
End If

Or else find where the error is occuring, and use the IF statement, there, telling it to go to the error handler... not sure why it's missing your error handling right off the bat, though.

--

"If to err is human, then I must be some kind of human!" -Me
 
I think the problem with Word loading is, it isn't actually an error, unless I close word and the rest of the code can't execute. It will happily create a read-only copy, in this case no error occurs.

I've acted on your advice - and added a more appropriate message (my headache's gone now!):

cmdSendLetter_Click_Error:
If Err.Number = 4198 Then MsgBox ("Please close your previously merged letter") _
& Chr(13) & ("then try again")

It's an improvement as it tells the user where the problem is and what to do about it, thanks for your help :)

 
You're welcome. As far as getting totally rid of the "locked" message as well, there may be a way to turn off messages in Word, but I don't know what that is. In Access, I know it's "DoCmd.Set Warnings = False"... then "DoCmd.SetWarnings = True" after whatever line(s) of code you wanted to get around the messages..

In Excel, it's something else that I don't recall at the moment, even though I used that just last week, or 2 weeks ago...

So, I'm sure there is some way for Word.

Does anyone know the line of code for turning "messages" on/off in Word?

--

"If to err is human, then I must be some kind of human!" -Me
 
turning "messages" on/off in Word?
Application.DisplayAlerts wdAlertsNone
Application.DisplayAlerts wdAlertsAll

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top