Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Browse Button Control 1

Status
Not open for further replies.

Dutt

Programmer
Aug 20, 2001
33
US
I'm trying to program a browse button where you can select a program on your hard drive and output the path/filename to a text box. I think I need a control to do this but not sure. Someone Please Help!!!!

Dutt
 
Hi, Dutt!

Here's codes what I think will help you.

Create Common Dialog control on form and name it cmnDialog. Create command button on form and name it pbBrowse. Copy following codes into codes window.

Public strOutputFileName As String 'Default output File name
'------------------------
Private Sub pbBrowse_Click()
On Error GoTo Err_pbBrowse_Click
Dim strFilter As String
Dim strFileName As String
Dim strOutputDocName As String
Dim objDialog As Object
Set objDialog = Me.cmnDialog.Object

strOutputDocName = "MyReportName"
strFilter = "All Files|*.*"

With objDialog ' Ask for new file location.
.DialogTitle = "Open File..."
.Filter = strFilter
.FileName = strOutputFileName
.CancelError = True
.FilterIndex = 1
.flags = &H4 Or &H2 Or &H800 Or &H400 'cdlOFNHideReadOnly + cdlOFNOverwritePrompt + cdlOFNPathMustExist
.ShowOpen
' If user responded, put selection as string variable's value.
If Len(.FileName) > 0 Then
'Remember current selection
strOutputFileName = .FileName

'Update textbox with full path string
me.txtLocation=strOutputFileName

End If
End With

Exit_pbBrowse_Click:
Exit Sub

Err_pbBrowse_Click:
If Err.Number <> 32755 Then 'An error No 32755 is generated
'when the user chooses the Cancel button.

MsgBox &quot;Error No &quot; & Err.Number & vbLf & Err.Description
End If
Resume Exit_pbBrowse_Click
End Sub


Aivars
 
Thanks Aivars

I tried to Create a Common Dialog control on my form and I get an error: The OLE isn't registered. To register reinstall. So I used REGSVR32 COMDLG16.OCX to see if it would register but gave me a load libray error. The code you provided is great and its exactly what I am looking for. If you know the cause of the OLE Error let me know.

Thanks for the help I really appreciate it!

Dutt
 
To do that, you will need:
a) a DriveListBox (Drive1)
b) a DirListBox (Dir1)
c) a FileListBox (File1)
d) a TextBox (txtChoice)

Then:


Private Sub Drive1_Change()
On Error Resume Next
Dir1.Path = Drive1.Drive
End Sub

Private Sub Dir1_Change()
Dim sFile As String
File1.Path = Dir1.Path
sPath = Dir1.Path
End Sub

Private Sub File1_DblClick()
Dim nCounter As Integer
Dim sFile As String

For nCounter = 0 To File1.ListCount - 1
If File1.Selected(nCounter) = True Then
sFile = File1.List(nCounter)
End If
Next

Me.txtChoice.Text = sPath & &quot;/&quot; & sFile

End Sub


I just copied and pasted this coding from a project I did 2 years ago. I customized it on the fly for you. But I think it should work. But basically, this is all you need to get started.

Good luck and let me know if it worked well




''Life is like a box of chocolate...''
 
Hi, Dutt again!

See at thread702-121993
Very nice code. Works without any control.

Good luck!
Aivars
 
Thanks Aivars,

Everything worked out great with the control!

Thanks for the help

Dutt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top