"Validating" file names is one of those things that no matter how hard you try you'll never get it 100% right. There are a loads of reasons when a file might not save, even if the name is valid, acess rights, disk space, problems with the file it's self, network issues...
Basically you have to trust the user a bit and try to pick up any basic errors.
With that in mind I found this was the simplest, and most 'bang for buck' type of function to use. It's easy and gets it right most of the time. You still need to manage errors well when you save the actual file though!!!
If (Me.txtFileName.Text Like "*[/\:*?""<>]*") Then
a = MsgBox("Invalid filename format, please try another, " _
& "Stuff like /, @, ~, ?, ! etc does not help.", , _
gsAppName & gsAppVersion)
Me.txtFileName.SetFocus
End If
End Sub
Here I've added it to the Exit event of a text box, so it runs each time the user leaves the text box. Another option would be to run the check at the end of a form, i.e when OK is pressed. You'll have to think about which method will work best for your application.
I think it's more appropriate to create a function that validates your form fields, then either
a) call it from the "OK" button, and pop up a msgbox telling them which one was wrong (the function would have to return a value telling you which one), or
b) call it from the TextBox_Exit Event and just change the backcolor of the textbox to indicate that the field was filled out incorrectly (learned that from "Professional Excel Development" LOL). Perform the check again when the "OK" button gets clicked and stop the user.
I also like to use the following lines of code to highlight the offending textbox:
.SelStart = 0
.SelLength = Len(.Value)
End With
--JP
Erotic incest stories....
Incestgrrls free incest stories. Sex incest. Mom son incest. Incest stories. Incest comics....
Free incest stories....
Cartoon incest. Incest grrl. Free incest pic. Father son incest. Incest porn. Family incest. Incest story....