How to display an error message then continue

T

Tdahlman

I have a Select Case that runs when I click a Command Button in my form.
When I click the button it Opens a folder on my network.

Here is my code.

Private Sub Project_Folder_Click()
Select Case Me.Project_Number
Case Is < 591
Me.Project_Folder_Hyperlink.Value = "H:\New Drive\" & Me.Project_Number
Case 591 To 999
Me.Project_Folder_Hyperlink.Value = "H:\New Drive\591 - 999\" &
Me.Project_Number
Case 1001 To 1500
Me.Project_Folder_Hyperlink.Value = "H:\New Drive\1001 - 1500\" &
Me.Project_Number
Case 1501 To 2000
Me.Project_Folder_Hyperlink.Value = "H:\New Drive\1501 - 2000\" &
Me.Project_Number
Case 2001 To 2500
Me.Project_Folder_Hyperlink.Value = "H:\New Drive\2001 - 2500\" &
Me.Project_Number
Case 2501 To 3000
Me.Project_Folder_Hyperlink.Value = "H:\New Drive\2501 - 3000\" &
Me.Project_Number
Case 3001 To 3500
Me.Project_Folder_Hyperlink.Value = "H:\New Drive\3001 - 3500\" &
Me.Project_Number
Case 3501 To 4000
Me.Project_Folder_Hyperlink.Value = "H:\New Drive\3501 - 4000\" &
Me.Project_Number
Case 4001 To 4500
Me.Project_Folder_Hyperlink.Value = "H:\New Drive\4001 - 4500\" &
Me.Project_Number
End Select
Me.Project_Folder.HyperlinkAddress = Me.Project_Folder_Hyperlink
End Sub

What I want to happen is if the Folder doesn't exist then I want it to
display a message that says "Project Folder does not exist. Please create the
necessary folder"
Then I want it to automatically open H:\New Drive\591 - 999 ... Or 1001 -
1500, etc. depending on which Case is true.

Thank you in advance for your help

Travis.
 
P

pietlinden

I have a Select Case that runs when I click a Command Button in my form.
When I click the button it Opens a folder on my network.

Here is my code.

Private Sub Project_Folder_Click()
Select Case Me.Project_Number
Case Is < 591
    Me.Project_Folder_Hyperlink.Value = "H:\New Drive\" & Me.Project_Number
Case 591 To 999
    Me.Project_Folder_Hyperlink.Value = "H:\New Drive\591 - 999\" &
Me.Project_Number
Case 1001 To 1500
    Me.Project_Folder_Hyperlink.Value = "H:\New Drive\1001 - 1500\"&
Me.Project_Number
Case 1501 To 2000
    Me.Project_Folder_Hyperlink.Value = "H:\New Drive\1501 - 2000\"&
Me.Project_Number
Case 2001 To 2500
    Me.Project_Folder_Hyperlink.Value = "H:\New Drive\2001 - 2500\"&
Me.Project_Number
Case 2501 To 3000
    Me.Project_Folder_Hyperlink.Value = "H:\New Drive\2501 - 3000\"&
Me.Project_Number
Case 3001 To 3500
    Me.Project_Folder_Hyperlink.Value = "H:\New Drive\3001 - 3500\"&
Me.Project_Number
Case 3501 To 4000
    Me.Project_Folder_Hyperlink.Value = "H:\New Drive\3501 - 4000\"&
Me.Project_Number
Case 4001 To 4500
    Me.Project_Folder_Hyperlink.Value = "H:\New Drive\4001 - 4500\"&
Me.Project_Number
End Select
    Me.Project_Folder.HyperlinkAddress = Me.Project_Folder_Hyperlink
End Sub

What I want to happen is if the Folder doesn't exist then I want it to
display a message that says "Project Folder does not exist. Please createthe
necessary folder"
Then I want it to automatically open H:\New Drive\591 - 999 ... Or 1001 -
1500, etc. depending on which Case is true.

Thank you in advance for your help

Travis.

You need to see if you folder exists first in your code.

Private Function FolderExists(ByVal strPath As String) As Boolean

If strPath <> vbNullString Then
If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"
FolderExists = Len(Dir(strPath)) > 0
Else
FolderExists = False
End If

End Function


Private Sub Command3_Click()
Dim strPath As String
strPath = Me.txtFolderName
If Not FolderExists(strPath) then
MkDir (strPath)
End If
'save your file here...
End Sub

In your case, though, if the folder doesn't exist, you can use MkDir
to create it and then save the file.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top