Log in

View Full Version : [SOLVED:] Using FileDialog to open and display FileName



technocraze
09-21-2007, 06:54 AM
Hi pals,

I would like to know how to display the FileName of the selected file and open it using FileDialog property. I have imported the necessary reference from the library - Microsoft Office Object Library 10.0. Tks

Control:
TextBox - Display FileName
Button - Open


Private Sub Command_Onclick()
Dim fd as FileDialog
Dim varSelected as Variant
set fd = Application.FileDialog(msopen....)
With fd
.MultiSelect = true
.Show
if . show = -1 then
for each varSelected .SelectedItem
Next
Else
MsgBox "Cancel"
End If
End with
End Sub

Oorang
09-21-2007, 10:19 AM
Something like this maybe?


Private Sub CommandButton1_Click()
Dim fd As FileDialog
Dim varSelected As Variant
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.AllowMultiSelect = True
If .Show = -1 Then
Me.TextBox1.Text = vbNullString
For Each varSelected In .SelectedItems
Me.TextBox1.Text = Me.TextBox1.Text & "," & varSelected
Next
Else
MsgBox "Cancel"
End If
End With
End Sub

technocraze
09-21-2007, 11:21 PM
First of all, tks for the prompt reply.

However, I am still encountering some issues when i stepped in the code to debug

Line

Me.Text0.Text = vbNullString
Me.Text0.Text = Me.Text0.Text & "," & varSeleced

Error message
Runtime error = '2185'
You cant reference a property or method for a control unless the control has a focus.

tks

technocraze
09-21-2007, 11:50 PM
Issue resolved. But the selected file still cannot be open and the name of the selected file is not display in the textbox. When the prog is executed, only , is displayed in the textbox



First of all, tks for the prompt reply.

However, I am still encountering some issues when i stepped in the code to debug




Me.Text0.Text = vbNullString
Me.Text0.Text = Me.Text0.Text & "," & varSeleced

Error message
Runtime error = '2185'
You cant reference a property or method for a control unless the control has a focus.

tks

Oorang
09-24-2007, 10:07 AM
Try using the value property instead of the text property.