Putting choices from a list box into a table

kupe

Registered User.
Local time
Today, 23:17
Joined
Jan 16, 2003
Messages
462
A word is chosen in a list box. Actually, there are 7 list boxes or so on the form. I need each word to appear in a text box on the same form.

When the 7 choices are made, could the seven words populate one field of MyTable, in code, please?
 
Try this.

Code:
sub addwords()

Dim rstable as DAO.recordset
Dim sWord1 as string, sWord2 as string....etc....sWord7 as string

sWord1 = me.yourtextfield1
sWord2 = me.yourtextfield2
.
.
etc


set rstable = currentdb.openrecordset("yourtable")
rstable.addnew
rstable.fields("yourfield") = sWord1 & " " & sWord2 & " ".....etc
rstable.update

end sub

Fuga.
 
Looks pretty amazing, Fuga. Off to try it. Many thanks.
 
Hi Fuga

Are sWord1, sWord2 etc the list boxes?
 
Not exactly.

sWord1 is a variable that gets its value from textfield1 in the sWord = me.textfield1 line.

The textfield1 should be a reference to your listbox1. Don´t know why I called it textbox1. Sorry if it was confusing.

Then it repeats with sWord2, sWord3 etc.

Fuga.
 
Excellent, Fuga. It's working well.

What I'd like to do is to have each choice in the list boxes show in a text box. In fact what would be best - can it be done? - is to have each word chosen appear in a single text box, one word after another, as in a sentence.

With or without, this is great, and I am very grateful. All the best
 
I´m not sure, but try some thing like this. Use the addwords() sub as an after update or maybe lost focus event of your listboxes.
Code:
sub addwords()

Dim sWord1 as string, sWord2 as string....etc....sWord7 as string

sWord1 = me.yourtextfield1
sWord2 = me.yourtextfield2
.
.
etc

Me.yourtextbox = sWord1 & " " & sWord2...etc

Me.refresh

end sub

Actually, I´m not sure you need code for this. You might be able to reference to your listboxes directly in the textbox control source.

Fuga.
 
What I had done was to put the following on to each list box click, with this on the final list box.

Me.txtSentence = Me.lstAdjective & " " & Me.lstManufacturer & " " & Me.lstModel & " " & Me.lstNetwork & " " & Me.lstStore & " " & Me.lstTariff & " " & Me.lstCountry
Me.txtCountry = Me.lstCountry

But yours looks much simpler. Thanks very much. In fact, I'm really grateful for this guidance on the whole thing, Fuga. The arrangement works brilliantly. (Is that magic Stockholm archipelago still there? I've been lost navigating there a few times. But what a great cruising ground.) Cheers
 
Is that magic Stockholm archipelago still there?

You bet!:cool:

And it´s particularly beautiful in autumn. But then again, winter is coming:(

Fuga.
 
... when the 365 islands and passages disappear beneath snow and icebergs, perhaps. Still, the world's changing weather may have you people growing hibiscuses and coconut palms before many centuries are done. Live long.

Cheers
 

Users who are viewing this thread

Back
Top Bottom