ItemData(0) returns nothing-why?

CarlyS

Registered User.
Local time
Today, 09:20
Joined
Oct 9, 2004
Messages
115
I am trying to use ItemData to fill in the first row of a combo box into control1 and the second row of the combo box to fill into control2.
This is what I've tried:

Private Sub Form_Load()
Me!Bx1LabelBox.Requery
Me!Bx1Label.Value = _
Me!Bx1LabelBox.ItemData(0)
End Sub

This worked for control1. Now I want to add the next part for Control2. Where/How do I do that? This does not work:

Private Sub Form_Load()
Me!Bx1LabelBox.Requery
Me!Bx1Label.Value = _
Me!Bx1LabelBox.ItemData(0)
End Sub

Private Sub Form_Load()
Me!Bx2LabelBox.Requery
Me!Bx2Label.Value = _
Me!Bx2LabelBox.ItemData(1)
End Sub

I am new to VB. Please help!

Carly
 
Carly,

How many form_loads do you have?

Totally confused by all of this!

Do you mean ListBox?

Wayne
 
I am trying to use ItemData to fill in the first row of a combo box into control1 and the second row of the combo box to fill into control2.

You can multi-select a list-box so that it has multiple rows, but a combo box doesn't do this unless this ability has been updated in a version of Access I don't have. But you COULD mean "first COLUMN" of the combo box, "second COLUMN" of the combo box...

WayneRyan's comments are also correct. There is only ONE form load event per form. If you have more than one event, only one of them is real. The other either has been superceded or has an alternate name - like OnFormLoad(2) or something like that. If you don't believe me, go into your code window, get into edit mode, and look at the list of entry points. Try to select the FormLoad event and see where it gets you.

You can have more than one set of actions in the same event code, but you will not have two events of the exact same flavor firing from one Windows event at the same time unless two windows (little w) are open and on-screen at the same time. Further, the FormLoad event won't happen in the screen that doesn't have focus unless you have a timer routine driving it.

So it is possible that the one you say "doesn't work" doesn't work because it is never being executed, having been superceded by the code in your other FormLoad event code.

By the way, if you are seriously talking "OnFormLoad" then a List Box and Combo Box are probably not active at the time. Did you perhaps mean "FormCurrent" event? Or were you thinking of an OnClick event for the list box or combo box?

I think you need to review your events in the help file, or if you have a book that describes events, read that chapter very carefully.
 
Thank you both for your reply. I will try to explain this better. I do not want to select two values from the list. I want the first control to select the first value and the second control to select the second value and so on for seven controls so that one value is stored in each control. I want these things to be automatically selected and I do not want anyone to have to click on them or touch them ever really.

These controls are on a subform which is linked to a mainform by a student's name. The combo box draws its options from a query so that the list selects behaviors that are specific to the student whose record is showing on the mainform. I want the first behavior on the student's list to go into the first control and the second behavior to go into the second control and so on for seven behaviors. The lists will change as behaviors are added or discontinued and I want those changes to be reflected on this subform.

I am sure I am using the wrong event. What event do you think might work?

I tried using the subform's OnCurrent property and I get the same result--only data in the first field. Should I be using an event on the controls' properties? Is there an event on the control that will run even if no one clicks or touches the control? I wasn't sure if there is so that is why I was using the form events.

I appreciate all your help!
 
Nevermind!
I got it working using macros instead, which is much better for me! Thank you so much for your help and your patience with me!

Carly
 
Just a quick note...
I believe there are only two events that fire on a subform... On Enter, On Exit.
Insert a breakpoint on all the events you have tried and see which one it halts on, if the breakpoint doesn't force you to go into your debugger then it never ran.
Once you find the correct event, then you can step through what you have to do to get what you want done.

Oops, I see I replied just after your last entry... glad you got it working. Try the breakpoints just for your info.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom