By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,422 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,422 IT Pros & Developers. It's quick & easy.

if anyone knows..how do you move info from a listbox? It just seems to select it and do nothing.

P: n/a
I have a subform where I have a subform with 20 options to select
from. When I set the multiselect property to simple and select
multiple options, nothing is stored. I have another table with
fieldID and fieldtype and I would like for evertime something is
selected in the listbox for a new entry to be created with that
fieldtype for the corresponding fieldID which is linked to the main
form. Basically, how do I get info from the listbox to go into the
subform and create new entries?? thanks anyone
Nov 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Alienz wrote:
I have a subform where I have a subform with 20 options to select
from. When I set the multiselect property to simple and select
multiple options, nothing is stored. I have another table with
fieldID and fieldtype and I would like for evertime something is
selected in the listbox for a new entry to be created with that
fieldtype for the corresponding fieldID which is linked to the main
form. Basically, how do I get info from the listbox to go into the
subform and create new entries?? thanks anyone


Using a subform may be easier :)

If you use a Listbox you need to manually read off the multi-selected
items and manually add them to the table (via code)
--
regards,

Bradley
Nov 13 '05 #2

P: n/a
Alienz wrote:
I have a subform where I have a subform with 20 options to select
from. When I set the multiselect property to simple and select
multiple options, nothing is stored. I have another table with
fieldID and fieldtype and I would like for evertime something is
selected in the listbox for a new entry to be created with that
fieldtype for the corresponding fieldID which is linked to the main
form. Basically, how do I get info from the listbox to go into the
subform and create new entries?? thanks anyone

Here is a sample routine I used. I have ColumnHeaders on in my listbox
so that is why I start intFor at 1 and 0. I want to add the record
with the order number if selected in a multi-select listbox and if it
does not exist. If it does exist, but this time is not selected, I want
to remove it from the table.

If you don't have the need to remove selections if they exist in the
table but aren't selected, you can change ListCount -1 and use
ItemsSelected. Review these commands in Help. Ex:

Dim Var As Variant
For each var in Me.ListBox.ItemsSelected
'get the value in the second col of the listbox
'since columns start at 0
strValue = Me.ListBox.Column(1,var)
Next

Anyway, here's the code.

Sub x()

Dim intFor As Integer
Dim strOrder As String
Dim rst As Recordset
Dim blnSelected As Boolean

For intFor = 1 To Me.ListBox.ListCount - 1
strOrder = Me.ListBox.Column(0, intFor)
blnSelected = Me.ListBox.Selected(intFor)
rst.FindFirst "OrderID = '" & strOrder & "'"
If rst.NoMatch Then
If blnSelected Then
rst.AddNew
rst!OrderID = strOrder
rst.Update
End If
Else
If Not blnSelected Then
rst.Delete
End If
End If
Next intFor

End Sub

Nov 13 '05 #3

P: n/a
thanks for the replies

Bradley- I don't mind using a subform but it's still not too clear how
to do it
Salad-
- I think recordset is a good idea but I'm not doing searches I'm using
a valuelist that is already determined.

I have a value list of 20 items so I could do a for loop for the 20
items:

sub t()
dim x as integer
dim y as variant
for (x<= 20)
if (Me.ListBox.Selected(x)) then TABLE2.value= variant
next x
end sub

- but when would this code run after update() ?

thanks :D

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #4

P: n/a
Alienz on the www wrote:
thanks for the replies

Bradley- I don't mind using a subform but it's still not too clear how
to do it
Salad-
- I think recordset is a good idea but I'm not doing searches I'm using
a valuelist that is already determined.
I wasn't doing searches either.
I have a value list of 20 items so I could do a for loop for the 20
items:
If you want. Since it appears you want to ADD records, not check to see
if it already exists for that key, you should use ItemsSelected. I
provided a routine. Your homework should be to highlight properties and
commands in code press the F1 key to learn about them.
sub t()
dim x as integer
dim y as variant
for (x<= 20)
if (Me.ListBox.Selected(x)) then TABLE2.value= variant
next x
I don't see how your
if (Me.ListBox.Selected(x)) then TABLE2.value= variant
does anything at all. I would add the records via a recordset and then
do a Requery on the form or subform. IOW, you need to use a recordset
to add the records. Either that or else use the GoToRecord and then run
a DOcmd.RUncommand accmdsaverecord for each record added. More of a
PITA than anything else using this method.



end sub

- but when would this code run after update() ?
Of the listbox? If you are doing/allowing a multiselect, you need to
determine when the update routine is to be run. So I would have a
command button that would run thru and add the records when pressed.
It's more up to you as to when/how you want to do this. That's more of
a design issue than anything else.

thanks :D


Nov 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.