I am using a MDI Form and several documents can be opened using

If i open a file then go back to open another file but click cancel or the "x" then it will open the last file.

so i need to know how to clear the "#1"

my code it:

FileName = ""
Data = ""
MDIForm1.CommonDialog1.Filter = "All Files(*.*)|*.*|Text Files(*.txt)|*.txt|Web Files(*.html;*.htm;*.shtml;*.shtm;*.xhtml;*.php;*.php3;*.phtml;*.css;*.js;)|*.html;*.htm;*.shtml;*.shtm;*.xhtml;*.php;*.php3;*.phtml;*.css;*.js;|Batch Files(*.bat;*.cmd;*.nt;)|*.bat;*.cmd;*.nt;|VB Files(*.vb;*.vbs;*.frm;*.vbp;)|*.vb;*.vbs;*.frm;*.vbp;"
On Error GoTo error
Me.Caption = MDIForm1.CommonDialog1.FileTitle
FileName = MDIForm1.CommonDialog1.FileName
Open FileName For Input As #1
Do Until EOF(1)

        Input #1, Data
        Me.Text1.Text = Me.Text1.Text + Data + vbCrLf
    EOF (1)
    Close #1
    FileName = ""
    Data = ""
GoTo endload

Any ideas

I have cleared the "FileName" and "Data" but it still does it so i need to find a way to stop it.

Recommended Answers

All 2 Replies

#1 refers to the file and the Close event will close the file.

two different ways are shown in the following...

Option Explicit

Private Sub Command1_Click()
End Sub

Private Sub OpenShowFile()

On Error GoTo OpenShowFileError

Dim FName As String, FNumb As Integer
Dim FileContents As String

CD.CancelError = True
CD.Filter = "Text Files *.txt|*.txt"
CD.FileName = vbNullString

If CD.FileName = vbNullString Then Exit Sub

FName = CD.FileName
FNumb = FreeFile

Open FName For Input As #FNumb
FileContents = Input(FileLen(FName), #FNumb)
Close #FNumb

Text1.Text = FileContents

Exit Sub

If Err.Number = 32755 Then Exit Sub 'user pressed cancel

End Sub

Good Luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.