How to open files using dialog box
VB Code:
Const forreading = 1, Forwriting = 2
Dim fs, f
Private Sub Form_Load()
CommonDialog1.Filter = "All Files(*.*)|*.*|Text files(*.*)|*.txt"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
Set f = fs.opentextfile(CommonDialog1.FileName, forreading)
Text1.Text = f.readall
f.Close :confused:
End If
End Sub
The above code is not working.Please correct errors if any
P.S It should prompt a dialog box and open a text file .
Re: How to open files using dialog box
What exactly are you trying to do? You can not open either of those files in runtime. Are you using VBA?
Re: How to open files using dialog box
if you are trying to open a form, do
where Form1 is the form you want.
If you want to open files, then you'll need a Command Dialog component. Right click on the toolbar, select components, and look for Microsoft Common Dialog 6.0, and tick it and then press ok. Insert it into your project and put the following into your code
VB Code:
commondialog1.Filter = "All|*.exe" ' Replace this with extensions you want
commondialog1.ShowOpen
Re: How to open files using dialog box
If this is VBA then there is no commondialog control. ;) VBA does give you some built in functions for displaying a "commondialog" box though. It differs depending on the office app your using.
Re: How to open files using dialog box
...although you can add the common dialog component to VBA if you have vb6 installed as well.
zaza
Re: How to open files using dialog box
Yes, but then you would also have to distribute the ocx along with the document or workbook etc. ;)
Re: How to open files using dialog box
I am trying to open a text box by using commondialog control. I am using vb 6.
Re: How to open files using dialog box
What do you exactly mean by "open a text box"?
If you mean trying to load a form file into your VB project in run time, then you are going to have problems. What RoboDog888 said (in 4th post) was correct. You can't just load it!
I don't know how to explain it any better, but if you're trying to do the above, short answer is no.
If it's anything else, explain!!!