View Full Version : Combo Not working
jmentor
02-25-2007, 05:13 AM
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
mdmackillop
02-25-2007, 05:38 AM
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.
jmentor
02-25-2007, 06:40 AM
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
jmentor
02-25-2007, 06:48 AM
MDMack
Forgot to mention that an error popped up telling me
to change the combo box to Value List
Jmentor
mdmackillop
02-25-2007, 07:29 AM
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
jmentor
02-25-2007, 07:38 AM
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
mdmackillop
02-25-2007, 07:44 AM
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.
jmentor
02-25-2007, 07:48 AM
Get File is a function I have in another database
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.