|
-
March 18th, 2001, 12:40 AM
#1
Dialog Box to open a text file.
I have this code to open a text file for Input.
Dim intFileNum As Integer, strName As String
Dim strFilter As String, NumberCorrect As Integer
Dim intNumberOfQuestions As Integer
Dim intLoadQuestions As Integer
Dim intLoadFields As Integer
Dim strTestName As String
Const conTitle As String = "Your Name"
Const conPrompt As String = "Enter your name:"
'frmQuizzerSplash.Show vbModal
strName = InputBox(conPrompt, conTitle)
intFileNum = FreeFile
strFilter = "Text Files (*.txt)|*.txt|" & "All files (*.*)|*.*"
cdlOpenfile.Filter = strFilter
cdlOpenfile.ShowOpen
g_strFileName = cdlOpenfile.FileName
'On Error GoTo FileOpenErr
Open g_strFileName For Input As #intFileNum
When I hit cancel on the Dialog box I get this error: Path/File Access Error
And it highlights this line: Open g_strFileName For Input As #intFileNum
Is there some more code I should have to make the dialog box just cancel?
-
March 18th, 2001, 09:00 AM
#2
Re: Dialog Box to open a text file.
Set the CancelError property of the cdlOpenfile common dialog box to True. Then in your code, place an On Error Goto ErrHndlr before the ShowOpen method as follows:
strName = InputBox(conPrompt, conTitle)
intFileNum = FreeFile
strFilter = "Text Files (*.txt)|*.txt|" & "All files (*.*)|*.*"
cdlOpenfile.Filter = strFilter
on error GoTo ErrHndlr 'Start the error handling
cdlOpenfile.ShowOpen
on error Goto 0 'Stop the error handling
g_strFileName = cdlOpenfile.FileName
Open g_strFileName for input as #intFileNum
...
More code here
....
Exit Sub
ErrHndlr:
' error handling code here, or you can leave it empty
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|