Click to See Complete Forum and Search --> : Select File Dialog
Parmenion
October 24th, 2001, 01:54 PM
What I have: A text field [tf_location] and a button
[b]What I need to do: When the user clicks the browse button, have the standard windows Select File Dialog pop up. When the user selects a file, the dialog closes and the path of that file is displayed in the text field.
The Problem: I am a java programmer and have no idea how to do this in VB. I am working in an MS Access environment.
Any answers would be greatly appreciated :)
DSJ
October 24th, 2001, 02:06 PM
Add the reference to the microsoft commondialog control to your project (Project, Components, etc.)
Place the CommonDialog control on your form along with a textbox and commandbutton and this code should work for you...
private Sub Command1_Click()
CommonDialog1.CancelError = true
on error GoTo Error_Handler
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.FileName
Exit Sub
Error_Handler:
'user hit Cancel Button....
End Sub
michi
October 24th, 2001, 03:25 PM
The previous post is right, I just want to add more. Let's assume you want to open a picture file:
private Sub Command1_Click()
on error GoTo Error_Handler
With CommonDialog1
' Set filters.
.Filter = "Picture Files (*.bmp;*.gif;*.ico;*.jpg;*.tif;*.tiff)|*.bmp;*.gif;*.ico;*.jpg;*.tif;*.tiff|All Files (*.*)|*.*"
' Specify default filter. (*.bmp)
.FilterIndex = 1
.CancelError = True
.DialogTitle = "Open A Picture"
.InitDir = strPath
.FileName = strFileName
' Display the Open dialog box.
.ShowOpen
End With
Text1.Text = CommonDialog1.FileName
exit sub
Error_Handler:
If Err.Number = cdlCancel Then
' User pressed Cancel button. Do nothing
else
msgbox err.description
end if
end Sub
Regards,
Michi
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.