I attached an mdb file which has a combox box on a form
that should list all text files in the directory which would then allow the user to select the required file. As you can see it is not working.
Can somebody give me a hand
Thanks
I attached an mdb file which has a combox box on a form
that should list all text files in the directory which would then allow the user to select the required file. As you can see it is not working.
Can somebody give me a hand
Thanks
Try
Private Sub Form_Load() Dim MyPath As String, MyName As String MyPath = CurrentProject.Path & "\" ' Set the path. MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry. Do While MyName <> "" ' Start the loop. If UCase(Right(MyName, 3)) = "TXT" Then Me.Text1.AddItem MyName End If MyName = Dir ' Get next entry. Loop End Sub
BTW, calling your combobox Text1 is a recipe for confusion. Something like cboMyFiles would be meaningful, and the prefix allows possible code handling of multiple combos, textboxes etc.
Last edited by Aussiebear; 04-27-2023 at 04:21 AM. Reason: Adjusted the code tags
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Thanks for your rapid reply MDMack
So far so good. Copied your code over and now the combo
box works.
The value (filename) in Text1 however is not passed over to the command button as in Call GetFile(Me.Text1)
Regards
Jmentor
MDMack
Forgot to mention that an error popped up telling me
to change the combo box to Value List
Jmentor
Apologies. Forgot about the Value List warning.
You didn't show your GetFile routine, so I'm not sure what you're doing with the found file. To open it, something like
Sub getfile(MyFile As String) Application.FollowHyperlink CurrentProject.path & "\" & MyFile End Sub
Last edited by Aussiebear; 04-27-2023 at 04:21 AM. Reason: Adjusted the code tags
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
MDMack
Aplogies
Could have sworn I attached the mdb. Obviously forgot to do so.
The code on the button is this.
Private Sub Command1_Click() If Len(Me.Text1) Then Call GetFile(Me.Text1) End If End Sub
In this lightof what you have supplied what do I need to change on the button to pick up the selected file
Thanks
Jmentor
Last edited by Aussiebear; 04-27-2023 at 04:22 AM. Reason: Adjusted the code tags
GetFile is not a built in function. You need to write some code to carry out whatever actions you require on the text file. My example opens the file.
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Get File is a function I have in another database