Full Version: Listbox Value
UtterAccess Forums > Microsoft® Access > Access Forms
Chris147
Hi all.
I have a listbox on form that displays a numeric value based upon a combo box selection. There is only ever one value in the list.
The problem: I need to be able to pass the displayed value to a variable in order to perform a calculation. I've tried everything I can thinlk of, but I can't retrieve the listbox value (I keep getting Null) - even though it is displaying properly...
Any ideas?
Thanks,
Chris.
MrSiezen
Do you have only one column? If not, is the bound column the correct one?
dallr
CODE
Me.YourListboxName.Column(1, 0)  [color="green"]'1 Is the first column and 0 is the first row  [/color]


Dallr

Edited by: dallr on Wed May 3 7:30:05 EDT 2006.
Chris147
Hi.
Been away from the PC for a while. Thanks for the info, it's appreciated.
Chris.
Chris147
Same old problem...
The listbox has only one column, and only one entry (which displays properly). I tried Me.lstCalc.Column(1, 0) and get the same Invalid Use of Null error - as though there was nothing there, except I know there is!
Will kicking the box help?
Chris.
dallr
Humm!!
Try the following before your Me.lstCalc.Column(1, 0)
e.lstCalc.Selection(0)=true
Me.lstCalc.Column(1, 0)
Dallr
Chris147
OK, so kicking the box doesn't help.
Tried the above, now I'm getting 'Method Or Data Member Not Found'
It's almost as if, once the list has been displayed on screen, its contents have been deleted...
There's nothing in the list to select, and yet there it is.
!?! Chris.
dallr
Can you post your db.
allr
Chris147
Not without getting fired!
old on and I'll submit all the code involved...
Chris147
Private Sub cboFrom_Change()
stCalc.SetFocus
lstCalc.Requery
Call GetCalc
End Sub
This displays a Long Integer from the bound table, depending upon the selection made in the combo box.
Private Sub GetCalc()
Me.lstCalc.SetFocus
Me.lstCalc.Selection(0) = True
lngCalc = Me.lstCalc.Column(1, 0)
End Sub
The code is now tripping up over "Me.lstCalc.Selection(0) = True", prior to inserting this line it tripped over "lngCalc = Me.lstCalc.Column(1, 0).
Does this help at all?
dallr
Sorry i did not realize you posted back.
Oposted selection when it should have been selected.
Me.Lstcalc.Selected(0) = True
Just to confirm you are physically seeing the entry in the listbox?
Dallr
Chris147
Yeah, make a selection in the combo and the list box displays the right data (long integer).
I've changed "Selection" to "Selected" and I'm back to invalid use of null...
The list uses the following RowSource:
SELECT tblData.lat1 FROM tblData WHERE ((tblData.la1)=Forms!frmCalculate!cboFrom);
dallr
1. In your list box property what number are you seeing for the bound Column?
2. By right data (long integer) you mean there is a value shown on the list box? eg. 1234
allr
Chris147
Bound Column = 1
Typical List Data = 115.131
dallr
Right all that is good.
Now lets take a look at how you are using it in your code.
Explain a little more in relation to your code posted at 05/03/06 12:05 PM.
. What are you clicking on that triggers the list box to say null.
2. Why are u using CALL GetCalc
etc......
Dallr
Chris147
The Change() event for the combo updates the list box, then should pass the list box value to either a variable or a text box (I've tried both, with the same result).
initially tried to run the entire sub routine in the same event, the Call to a separate function was out of desparation (occasionally, in VB, this will resolve an issue. But then, in VB, I'd just reference the list box .Caption and get what I want!).
dallr
1. Firstly your combo box should only have the following code:
me.lstCalc.Requery
. Where are you passing the lngCalc variable to.
Dallr
Chris147
I haven't passed the variable anywhere yet - I'm stil trying to populate it.
ill delete the unnecessary code and see what happens...
BTW Thanks for your help in this Dallr, it's appreciated.
Chris.
Chris147
No change.
Regardless of the fact that the list box clearly updates and displays the correct info when a selection is made in the combo box, attempts to reference this list box info returns Null.
dallr
No problem glad to help!!!
What you can do to test is to have the following in your combo event.
me.lstCalc.Requery
msgbox Me.lstCalc.Column(1, 0)
allr
Chris147
!
nvalid Use Of Null!
How can there be nothing in a list box when it's right there on screen?
dallr
Boi!!
The last thing i can say is delete the listbox. Then save and close your form. Compact and repair the DB. Then recreate the list box and reenter the same code with the new list box name.
When give me a shout.
Dallr
Chris147
Will do judt that Dallr.
omorrow. It's 19:02 here and time to call it a day.
Thanks again for your help, I may just fly out to the Caribbean to shake your hand...
Chris.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.