I am attempting to open a word document from an Access DB using a bit of VBA code. The document itself is also created from within the database and is automatically named using the record’s Permit Number field. I have an On Error statement to handle the case when this document has not yet been created.
Now this code was working fine and then MS decided to change the Word extension from doc to docx, so now depending on when the document was created, it could be named differently. So I put in a another layer of error handling. If fails on its attempt to open the doc file it goes to try and open the docx file. But if it still fails, I want it to use the original error handler, so I have two On Error statements. I thought this would be fine, but apparently it doesn’t recognize the second one because the code crashes at this point.
Is this not a valid approach? What should I be doing to handle this situation?
Code Follows:
Private Sub cmdEditTerms_Click()
On Error GoTo Try_DOCX_Extension
Dim Path As String
Path = DLookup("[Path]", "Region Data") & "\Region_" & DLookup("[Region]", "Region Data")
strInput = Path & "\TCReports\" & Me![PermitNumber] & ".doc"
Application.FollowHyperlink strInput, , False
Exit Sub
Try_DOCX_Extension:
On Error GoTo NotYetThere
strInput = strInput & "x"
Application.FollowHyperlink strInput, , False
Exit Sub
NotYetThere:
MsgBox ("This Terms and Conditions document hasn't been created yet.")
End Sub
Now this code was working fine and then MS decided to change the Word extension from doc to docx, so now depending on when the document was created, it could be named differently. So I put in a another layer of error handling. If fails on its attempt to open the doc file it goes to try and open the docx file. But if it still fails, I want it to use the original error handler, so I have two On Error statements. I thought this would be fine, but apparently it doesn’t recognize the second one because the code crashes at this point.
Is this not a valid approach? What should I be doing to handle this situation?
Code Follows:
Private Sub cmdEditTerms_Click()
On Error GoTo Try_DOCX_Extension
Dim Path As String
Path = DLookup("[Path]", "Region Data") & "\Region_" & DLookup("[Region]", "Region Data")
strInput = Path & "\TCReports\" & Me![PermitNumber] & ".doc"
Application.FollowHyperlink strInput, , False
Exit Sub
Try_DOCX_Extension:
On Error GoTo NotYetThere
strInput = strInput & "x"
Application.FollowHyperlink strInput, , False
Exit Sub
NotYetThere:
MsgBox ("This Terms and Conditions document hasn't been created yet.")
End Sub