Evaluate ListBox Value

A

alex

Hello,

using Access '03...

I have a form which contains an unbound listbox. The listbox row
source is a query that sums a value.

The listbox works fine...it displays the appropriate value (I requery
the listbox whenever information changes).

What I cannot do, however, is write code to evaluate the value of the
listbox (null or otherwise).

I've tried writing code that looks for isnull or me.value = N...no
luck.

What i'm looking to do is display a label (or even a msgbox) on the
form when the listbox value is > 5:

e.g., if me.lstHours.value > 5 then
me.lblWarning.visible = true

any help would be appreciated!
alex
 
W

Wayne-I-M

you need to give more information about what you are looking for to get a
better answer and also "when" you want to run the code


If Me.ListName = 5 Then
Me.lblWarning.Visible = True
Else
Me.lblWarning.Visible = False
End If

or lots of other "stuff" eg

Dim msg, style, title, ctext, responce, mystring
If Me.ListName = 5 Then
msg = "Some message here"
style = vbYesNo
title = "SomeTitle here"
responce = MsgBox(msg, style, title)
If responce = vbYes Then
'do something else here'
End If
End If
 
A

alex

you need to give more information about what you are looking for to get a
better answer and also "when" you want to run the code

If Me.ListName = 5 Then
Me.lblWarning.Visible = True
Else
Me.lblWarning.Visible = False
End If

or lots of other "stuff" eg

Dim msg, style, title, ctext, responce, mystring
If Me.ListName = 5 Then
msg = "Some message here"
style = vbYesNo
title = "SomeTitle here"
responce = MsgBox(msg, style, title)
If responce = vbYes Then
'do something else here'
End If
End If

--
Wayne
Trentino, Italia.













- Show quoted text -

Thanks Wayne,

What I'm looking for is to display a lable whenever the value of the
listbox is greater than 5.

I don't know where to run/place the code. I just tried running the
code (above) in the form's After Update event and the list box's After
Update event. It did not work.

For some reason, I can see a value but cannot evaluate it!
alex
 
D

Dale Fye

Is your listbox rowsource returning one value, or more than one value? If
only one, why are you using a listbox and not a textbox?

If it returns only a single value, and you want to use this value, you can
refer to it in code using:

Forms("formName").Controls("ListControlName").ItemData(0)

By using this, the value does not have to be selected, so you could
reference this value as soon as you requery the rowsource of the listbox.

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
A

alex

Is your listbox rowsource returning one value,  or more than one value? If
only one, why are you using a listbox and not a textbox?

If it returns only a single value, and you want to use this value, you can
refer to it in code using:

Forms("formName").Controls("ListControlName").ItemData(0)

By using this, the value does not have to be selected, so you could
reference this value as soon as you requery the rowsource of the listbox.

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.









- Show quoted text -

Hi Dale,

My listbox row source is returning one value. I don't know how to get
this value with a textbox.

With a listbox, I can provide a query for the row source (and it works
fine). With a textbox, however, there's no such row source. How can
I accomplish the same thing (a value from a query into a listbox) with
a textbox?

Thanks for your help.
alex
 
D

Dale Fye

In the textbox controlSource property enter something that looks like:

ControlSource:=DLOOKUP("FieldName", "yourQuery")

Substitute the name of the query you are using as the rowsource for the
listbox for "yourQuery", and the name of the field you are returning for
"FieldName".

The textbox has a requery method too, so you if the query uses values from
controls on your form, then you can requery the textbox in the afterupdate
event of those controls as well.

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
A

alex

In the textbox controlSource property enter something that looks like:

ControlSource:=DLOOKUP("FieldName", "yourQuery")

Substitute the name of the query you are using as the rowsource for the
listbox for "yourQuery", and the name of the field you are returning for
"FieldName".

The textbox has a requery method too, so you if the query uses values from
controls on your form, then you can requery the textbox in the afterupdate
event of those controls as well.

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.









- Show quoted text -

Thanks Dale, the Dlookup worked.

I still cannot, however, reference the value in the textbox. I must
not be using the right code!

If you had a hidden label on a form and you wanted that lable to
become visible if the value of the textbox exceeded 5, how would you
write the code and where would you put it?...

alex
 
D

Dale Fye

Alex,

It depends on what is influencing the value in this textbox.

The first place I'd put it is in the forms current event; something like:

Private sub Form_Current

me.lblHidden.Visible = (me.txtYourControl.Value >5)

End sub

You would also need to put this code anywhere that you requery the value of
the textbox, after you have done the requery.

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
A

alex

Alex,

It depends on what is influencing the value in this textbox.

The first place I'd put it is in the forms current event; something like:

Private sub Form_Current

     me.lblHidden.Visible = (me.txtYourControl.Value >5)

End sub

You would also need to put this code anywhere that you requery the value of
the textbox, after you have done the requery.

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.









- Show quoted text -

Thanks Dale,
I'll give that a try...I really appreciate your help!
alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ListBox help 1
Access Cannot select items in listbox 1
Listbox beforeupdate 2
Requery listbox 1
Vertical scroll bar display 3
Retrieve selected value from ListBox 9
Faster DCount or Query 6
Listbox query 3

Top