PDA

View Full Version : Solved: Combo Box Code Example



twotinners
06-12-2006, 09:19 PM
This is Newbie Code and I'm in learning mode ...so be gentle :help :

If I understand it properly (and I probably don't), the following code is SUPOSE to populate 5 dropdown comboxes with the same data from the same seperate text file. Am I even close ?

________________________________________________________

Private Sub Document_New()
Dim FFile As Integer
FFile = FreeFile
Dim i As Integer
Dim Temp As String
OpenTextFile("c:\Down\Employee_Name_and_ID.txt", ForAppending, _
TristateFalse) FOR Random As #FFile

i = 1

Do Until EOF(FFile)

Get #FFile, i, Temp
ComboBox1.AddItem Temp
ComboBox2.AddItem Temp
ComboBox3.AddItem Temp
ComboBox4.AddItem Temp
ComboBox5.AddItem Temp

i = i + 1
Loop
Close #FFile
End Sub
_________________________________________________
Private Sub ComboBox1_Click()
End Sub
_________________________________________________
Private Sub ComboBox2_Click()
End Sub
_________________________________________________
Private Sub ComboBox3_Click()
End Sub
_________________________________________________
Private Sub ComboBox4_Click()
End Sub
_________________________________________________
Private Sub ComboBox5_Click()
End Sub


Am I getting Warm or am I still STONE COLD?

Boy I'll be glad when this nightmare Word Form is DONE

Dave :bug:

fumei
06-13-2006, 12:29 PM
Nightmare? Only because you are beginning.

Yes you are warm. Concepts are good. What exactly are you asking for here?

mdmackillop
06-13-2006, 01:03 PM
A similar method.


Private Sub FillCombos()
Dim Temp As String
MYFILE = "c:\Down\Employee_Name_and_ID.txt"
Open MYFILE For Input As #1 ' Open file for input.
Do While Not EOF(1) ' Check for end of file.
Line Input #1, Temp ' Read line of data.
ComboBox1.AddItem Temp
ComboBox2.AddItem Temp
ComboBox3.AddItem Temp
ComboBox4.AddItem Temp
ComboBox5.AddItem Temp
Loop
Close #1 ' Close file.
End Sub

twotinners
06-13-2006, 07:03 PM
Fumei: to answer your question... I can't get my example to work. The combos are blank.

Mdmackillop: Your example actually looks real easy to follow and I just about understand it but I couldn't find a reference to "FillCombos" in word 2000 (I use the help button a lot). Is that for a different version of Word because I could'nt get that to work, but again, it looks very logical.

Thoughts, ideas, :banghead: ?

Please take a look at my attached file. It does not include the txt file as the source of the data. Any txt should suffice if named as referenced.

As always, thank you for any advice and assistance.

VB Newbie :dau: (I can't get enough of the smileys)

3275

mdmackillop
06-14-2006, 12:01 AM
Hi TwoTinners,
The name of a sub can be anything at all, (except for some reserved names due to happen on certain events)
I've tweaked your template to fill the combos when a new file is created from it.
Regards
MD

twotinners
06-14-2006, 09:14 AM
Mdmackillop: YOU ARE A GOD. :bow: :ipray:

I think I'm starting to see the light and "beginning" to understand.

It works and it does EXACTLY what I want it to do.

Thanks again :thumb

VB Newbie Dave

PS: A big thanks to Fumei too for all the assistance :yes