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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Advanced Error Handling 1

Status
Not open for further replies.

Mke85

IS-IT--Management
Oct 4, 2010
33
CA
Good Morning All,

I have an error handling problem here that I can't quite wrap my head around. What my code does so far; When the cmdView button is clicked, I have used various fields to compile a string which is used to open a pdf file directly in the main Electronic Pub directory. Error case if that pdf file doesnt exist in that directory, it will than open a sub folder within the main Electronic Pub directory that contains the specific pdfs. The cmdView button can only be clicked if a pdf is available in either the main Electronic pub directory or a sub directory.

The problem I am having is: What if the directory is no longer available on the network? My code will run through the first chunk error out "Run Time Error 490, cannot open specified file", error out and then jump to Err_OpenPubDirectory. From there it will error out "Run Time Error 490, cannot open specified file"
as well because the folder isnt available.

I can't quite figure out how to provent the sub from stopping. I've looked into "error cases" but since it is the same error that is being produced I figured that wouldnt work.

Private Sub cmdView_Click()
'View electronic pub code.
On Error GoTo Err_OpenPubDirectory
Dim ElectronicPub As String
ElectronicPub = Replace(txtCFTONumberNDID, "-", "")
ElectronicPub = Replace(ElectronicPub, "/", "")
ElectronicPub = ElectronicPub & " - " & Description & " - " & Language & ".pdf"
Application.FollowHyperlink "M:\2.0 TECH BRANCH\2.8 Publications\2.8.4 CFTO\2.8.4.1 Electronic CTFO\" & ElectronicPub
ElectronicPub = vbNullString
Exit Sub
Err_OpenPubDirectory:
' On Error GoTo Err_MissingPubDirectory
ElectronicPub = Replace(ElectronicPub, ".pdf", "")
Application.FollowHyperlink "M:\2.0 TECH BRANCH\2.8 Publications\2.8.4 CFTO\2.8.4. Electronic CTFO\" & ElectronicPub
ElectronicPub = vbNullString
Exit Sub
'Err_MissingPubDirectory:
' MsgBox (Err.Description & " Please contact the Master Tech Librarian.")
' Exit Sub
End Sub

Thanks for the help!
 
Haha I never claimed to be a good VBA programmer but this helped alot! With the dir function, all problems have been fixed.

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top