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 Code Trouble

Status
Not open for further replies.

bhujanga

Programmer
Oct 18, 2007
181
US
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
 
What about this ?
Code:
Private Sub cmdEditTerms_Click()
Path = DLookup("Path", "Region Data") & "\Region_" & DLookup("Region", "Region Data") & "\TCReports\"
strInput = Dir(Path & Me!PermitNumber & ".doc*")
If strInput = "" Then
  MsgBox "This Terms and Conditions document hasn't been created yet."
Else
  Application.FollowHyperlink Path & strInput, , False
End If
End Sub

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

Part and Inventory Search

Sponsor

Back
Top