473,387 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
4 2743
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: amber | last post by:
Hello, I'm trying to set up defaults on a form, that populates a listbox, but with no items selected when it first loads. I have code where if an associated check box is checked, the listbox is...
2
by: Sally | last post by:
I have a simple multiselect listbox with a rowsorce of MemberID, MemberName, SendLetter. SendLetter is a Yes/No field. What is the code to set SendLetter to Yes when the user selects MemberName? I...
2
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However,...
8
by: tshad | last post by:
I have a string that I read from my database: 1|8|5620|541 These are all values in my ListBox. I want to select each of these items (4 of them - but could be many more). At the moment I am...
8
by: Steve Schroeder | last post by:
For some reason I cannot get the OnSelectedIndexChanged event to fire for a listbox I have on a page. I'm able to populate the listbox with data from a stored procedure, but cannot trigger the...
18
by: Dave Sauny | last post by:
Ok, its a friday, I'm at work and I cant get this to work: I have 3 listboxes on one tab control page. when i select an item in listbox1 i want whatever is selected on the other 2 listboxes...
10
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web...
0
by: ManConfusedByMouse | last post by:
Hi all, I AM HAVING PROBLEMS UNDERSTANDING THE UPDATING BEHAVIOR/TIMING OF A WINDOWS.FORMS.SCROLLBAR COMPONENT... quick apology for my sorry posterior if posting in wrong place -- haven't much...
15
by: Doogie | last post by:
I have a .net app that a user currently enters a number in a text box, hits a button and a data call is executed. She wants the ability to enter in multiple numbers (up to 100). So to make...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.