Connecting Tech Pros Worldwide Forums | Help | Site Map

Programatically fill a combobox

Geir Baardsen
Guest
 
Posts: n/a
#1: Nov 13 '05
Hi!

I have several textfiles on disk like:

Thing 1
Thing 2

etc...

On a form I have two combo-boxes. When user chooses from Combo1
(predefined items) I want the second combo-box to load the text files
according to which item user chooses in Combo1.

Is there anybody that know how I do this?

The reason why is because the textfiles contain so much text (and are
so many) I don't want to put it in the code like:

if Combo1.ListItem = 0 then

Me!Combo2.Items.Rowsource = "Thing 1;Thing 2; etc"


End if

The textfiles will also be altered from time to time, but will always
contain items belonging to Combo1.

Thanks!

Me.Name

shumaker@cs.fsu.edu
Guest
 
Posts: n/a
#2: Nov 13 '05

re: Programatically fill a combobox


'Me!Combo2.Items.Rowsource = "Thing 1;Thing 2; etc"'

How bout you read the items from the text file into an output string
stream(or just append to a regular string) using a loop that gets each
line into the string and appends a ';', then assign the string to
RowSource.

If I were you though, I would create a table and paste the items from
the text file into the table, then you can use an SQL query for your
row source:

SELECT MyListOfOptions FROM MyTable;

If you ever want to edit the options available, then it's as easy as
editing the table.

Salad
Guest
 
Posts: n/a
#3: Nov 13 '05

re: Programatically fill a combobox


Geir Baardsen wrote:
[color=blue]
> Hi!
>
> I have several textfiles on disk like:
>
> Thing 1
> Thing 2
>
> etc...
>
> On a form I have two combo-boxes. When user chooses from Combo1
> (predefined items) I want the second combo-box to load the text files
> according to which item user chooses in Combo1.
>
> Is there anybody that know how I do this?
>
> The reason why is because the textfiles contain so much text (and are
> so many) I don't want to put it in the code like:
>
> if Combo1.ListItem = 0 then
>
> Me!Combo2.Items.Rowsource = "Thing 1;Thing 2; etc"
>
>
> End if
>
> The textfiles will also be altered from time to time, but will always
> contain items belonging to Combo1.
>
> Thanks!
>
> Me.Name[/color]

You can string them together as mentioned in another post. A problem
may occur since the string that can be concatenated is limited. I'm not
sure...it may be 2048 characters.

Check out RowSourceType and then find the info for creating a
UserDefinedFormat. Then you can have large sets of data...but you
should be able to program.
pietlinden@hotmail.com
Guest
 
Posts: n/a
#4: Nov 13 '05

re: Programatically fill a combobox


Hey Steve Jorgensen or Lyle,
can you do this kind of thing in ADO? basically, read a delimited
textfile into a recordset-type thing (virtual table, essentially) and
then assign the result as the rowsource for the combobox? I would
think that you could call it by doing something like

Function CreateList(byval strFileName as string) As ADODB.Recordset
.... or some such thing.

Lyle Fairfield
Guest
 
Posts: n/a
#5: Nov 13 '05

re: Programatically fill a combobox


pietlinden@hotmail.com wrote:[color=blue]
> Hey Steve Jorgensen or Lyle,
> can you do this kind of thing in ADO? basically, read a delimited
> textfile into a recordset-type thing (virtual table, essentially) and
> then assign the result as the rowsource for the combobox? I would
> think that you could call it by doing something like
>
> Function CreateList(byval strFileName as string) As ADODB.Recordset
> ... or some such thing.[/color]

Surely the listbox simply translates the "recordset-type thing" to a
string anyway, so why would one translate the string to a recordset first?

Assuming you can read the textfile just set the row source type to
valuelist, and the rowsource to the string. I often do my list and combo
boxes this way even when they are based on a query.


--
--
Lyle

"The aim of those who try to control thought is always the same. They
find one single explanation of the world, one system of thought and
action that will (they believe) cover everything; and then they try to
impose that on all thinking people."
- Gilbert Highet
Br@dley
Guest
 
Posts: n/a
#6: Nov 13 '05

re: Programatically fill a combobox


In news:Ehece.17491$If1.4008708@read2.cgocable.net,
Lyle Fairfield <lylefair@yahoo.ca> said:[color=blue]
> pietlinden@hotmail.com wrote:[color=green]
>> Hey Steve Jorgensen or Lyle,
>> can you do this kind of thing in ADO? basically, read a delimited
>> textfile into a recordset-type thing (virtual table, essentially) and
>> then assign the result as the rowsource for the combobox? I would
>> think that you could call it by doing something like
>>
>> Function CreateList(byval strFileName as string) As ADODB.Recordset
>> ... or some such thing.[/color]
>
> Surely the listbox simply translates the "recordset-type thing" to a
> string anyway, so why would one translate the string to a recordset
> first?
> Assuming you can read the textfile just set the row source type to
> valuelist, and the rowsource to the string. I often do my list and
> combo boxes this way even when they are based on a query.[/color]

Isn't there a limit on the length that string can be?
--
regards,

Bradley

A Christian Response
www.pastornet.net.au/response


Lyle Fairfield
Guest
 
Posts: n/a
#7: Nov 13 '05

re: Programatically fill a combobox


Br@dley wrote:[color=blue]
> In news:Ehece.17491$If1.4008708@read2.cgocable.net,
> Lyle Fairfield <lylefair@yahoo.ca> said:[/color]
[color=blue][color=green]
>>Assuming you can read the textfile just set the row source type to
>>valuelist, and the rowsource to the string. I often do my list and
>>combo boxes this way even when they are based on a query.[/color][/color]
[color=blue]
> Isn't there a limit on the length that string can be?[/color]

I can't comprehend a list box with so many choices that it approaches
any limit whatever, After 20 or so choices I find a different way. A
list box of a few thousand items is, IMO, quite ludicrous. SO my answer
is, "Dunno, Don't Care!".

There is a limit to the size of any list. Of course that's not including
the list of Texas executions which is infinite, but these are Divine
works of Men of God!

--
--
Lyle

"The aim of those who try to control thought is always the same. They
find one single explanation of the world, one system of thought and
action that will (they believe) cover everything; and then they try to
impose that on all thinking people."
- Gilbert Highet
Salad
Guest
 
Posts: n/a
#8: Nov 13 '05

re: Programatically fill a combobox


Lyle Fairfield wrote:[color=blue]
> Br@dley wrote:
>[color=green]
>> In news:Ehece.17491$If1.4008708@read2.cgocable.net,
>> Lyle Fairfield <lylefair@yahoo.ca> said:[/color]
>
>[color=green][color=darkred]
>>> Assuming you can read the textfile just set the row source type to
>>> valuelist, and the rowsource to the string. I often do my list and
>>> combo boxes this way even when they are based on a query.[/color][/color]
>
>[color=green]
>> Isn't there a limit on the length that string can be?[/color]
>
>
> I can't comprehend a list box with so many choices that it approaches
> any limit whatever, After 20 or so choices I find a different way. A
> list box of a few thousand items is, IMO, quite ludicrous. SO my answer
> is, "Dunno, Don't Care!".[/color]

I agree a few 1000 items is overkill. 20 choices? What happens if you
have 21 items? A list/combobox can handle more easily enough.

If you have a few rows but lots of columns you run out of string space.
The best way to do it is to create a user defined function. Using a
string is useful for small numbers of rows/cols.
[color=blue]
>
> There is a limit to the size of any list. Of course that's not including
> the list of Texas executions which is infinite, but these are Divine
> works of Men of God!
>[/color]
Alan Webb
Guest
 
Posts: n/a
#9: Nov 13 '05

re: Programatically fill a combobox


Guys,
Whatever happened to callback functions. These were all the rage with
Access 97. If they are still supported then you can supply the data to your
function any which way. The mvp site should have samples of these.
--
Alan Webb
knoNOgeek@SPAMhotmail.com
"It's not IT, it's IS"

"Geir Baardsen" <geir_baardsen@hotmail.com> wrote in message
news:35f9d8b7.0504280647.56df3969@posting.google.c om...[color=blue]
> Hi!
>
> I have several textfiles on disk like:
>
> Thing 1
> Thing 2
>
> etc...
>
> On a form I have two combo-boxes. When user chooses from Combo1
> (predefined items) I want the second combo-box to load the text files
> according to which item user chooses in Combo1.
>
> Is there anybody that know how I do this?
>
> The reason why is because the textfiles contain so much text (and are
> so many) I don't want to put it in the code like:
>
> if Combo1.ListItem = 0 then
>
> Me!Combo2.Items.Rowsource = "Thing 1;Thing 2; etc"
>
>
> End if
>
> The textfiles will also be altered from time to time, but will always
> contain items belonging to Combo1.
>
> Thanks!
>
> Me.Name[/color]


Closed Thread


Similar Microsoft Access / VBA bytes