|
-
Jun 16th, 2007, 08:22 PM
#1
Thread Starter
Lively Member
-
Jun 16th, 2007, 08:32 PM
#2
Re: Open a filedialog
You can do something like this:
Code:
Private Sub Command2_Click()
Dim sText As String
On Error GoTo ErrHandler
With CommonDialog1
.CancelError = True
.Filter = "General Modules (*.bas)|*.bas"
.ShowOpen
If Not .FileName = "" Then
'write selected file name into textbox
Text1.Text = .FileName
'or if you want to load text from file then use this instead
'NOTE: you will need to set Multiline and ScrollBars properties for your textbox
Open .FileName For Input As #1
sText = Input(LOF(1), #1)
Close #1
Text1.Text = sText
sText = ""
End If
End With
Exit Sub
ErrHandler:
Err.Clear
Exit Sub
End Sub
-
Jun 16th, 2007, 08:33 PM
#3
Thread Starter
Lively Member
Last edited by Brian M.; Jun 16th, 2007 at 10:36 PM.
-
Jun 16th, 2007, 08:35 PM
#4
Re: Open a filedialog
You're welcome. Make sure you read the comments...
-
Jun 16th, 2007, 08:36 PM
#5
Thread Starter
Lively Member
Re: Open a filedialog
You are too fast... Thanks I got it now...
-
Jun 16th, 2007, 10:02 PM
#6
Thread Starter
Lively Member
Re: Open a filedialog / Re: Variable Not Defined
Ok, when I run this program and click the open path button, I get a Compile Error: variable not defined. It highlights the Private Sub getpathbtn_Click() in yellow and it highlights the CommonDialog1 in blue. I only have a button named getpathbtn and a text field named dbpathtxt. I am running vb 6.0 enterprise w/service pack 6 on 98se.
Do I have to dim CommonDialog1 as something or maybe declare it? What about libraries? Do I need to go check a dll? And if I do, what do I dim it as, or what library do I click? See code below. Thanks again.
VB Code:
Option Explicit
Dim mess As Integer
Private Sub getpathbtn_Click() 'highlights this whole line in yellow
On Error GoTo ErrHandler
With CommonDialog1 'highlights CommonDialog1 in blue
.CancelError = True
.Filter = "General Modules (*.mdb)|*.mdb"
.ShowOpen
If Not .FileName = "" Then
dbpathtxt.Text = .FileName
Else
mess = MsgBox("Not a valid path to a database.", vbOKOnly)
End If
End With
Exit Sub
ErrHandler:
Err.Clear
Exit Sub
End Sub
-
Jun 16th, 2007, 10:45 PM
#7
Re: Open a filedialog
you need to add a commondialog control to your form
go to project > components and tick microsoft common dialog control 6.0
then add a commondialog control to your form from the toolbox
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jun 16th, 2007, 10:58 PM
#8
Thread Starter
Lively Member
Re: Open a filedialog
Thank you very much. Its working, for now. I was searching around in references. Well, I was close...
-
Jul 22nd, 2011, 02:05 PM
#9
Junior Member
Re: [RESOLVED] Open a filedialog
How do you leave the file path away so you would only have text.txt ?
-
Jul 22nd, 2011, 02:14 PM
#10
Re: [RESOLVED] Open a filedialog
Use the dialog's .FileTitle property
-
Jul 22nd, 2011, 02:25 PM
#11
Junior Member
Re: [RESOLVED] Open a filedialog
Smooth LaVolpe.
It works.
Thanks.
-
Jul 22nd, 2011, 02:28 PM
#12
Re: [RESOLVED] Open a filedialog
It often boils down to people now willing to explore properties of the given object.
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
|