PDA

View Full Version : detect list box value



CFDM
12-05-2006, 01:59 PM
I have a list box that is requeried after a vlaue is chosen in a combo box on the same form.

How can i detect the value in a list box without the user having to select it?:banghead: It does requery correctly. PLEASE HELP!

COME ON PEOPLE, SOMEONE HAS TO KNOW THIS!!

Saurabhk
12-05-2006, 03:30 PM
Hi CFDM,

I don't really understand your question. Would you be able to explain it in bit more detail

CFDM
12-06-2006, 06:14 AM
I have a list box that populates based on the value selected in the combo box. The value is there, but unless it is clicked it still reads as null in the code.

OBP
12-06-2006, 08:28 AM
Until a selection is made by clicking on a row in the List box it has no "value" only a "Rowsource" which contain the value(s).

CFDM
12-06-2006, 08:31 AM
duh!!!!!!!!!!!!!!!!!! i'm trying to figure out how it can detect the value without clicking in the list box-THE VALUE IS THERE!

OBP
12-06-2006, 08:49 AM
Try

MsgBox Me.ListBoxName.RowSource

where ListBoxName is the actual name of your List box.

CFDM
12-06-2006, 09:21 AM
This is the code that got it to work

Private Sub Form_Open(Cancel As Integer)
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim strPhone As String


Set rst = New ADODB.Recordset

rst.CursorLocation = adUseClient
strSQL = "SELECT tblUserInfo.Phone as Phone " _
& "FROM tblUserInfo " _
& "WHERE tblUserInfo.User = '" & Me.txtUser & "';"

rst.Open strSQL, CurrentProject.Connection
If rst.EOF Then
MsgBox ("Either there are no records for that User or you may have entered the name incorrectly.")
Else
Me.txtPhone = rst("Phone")

End If
rst.Close
Set rst = Nothing


End Sub

OBP
12-06-2006, 10:41 AM
Either your original question is badly worded, or this is a very hard way to go about it.
If the User chooses someone from a Combo, then that someone must exist, unless you have allow NotInList set to "yes" and why would you?
You can do the same check with this after the requery
if Me.ListBoxName.RowSource = "" then
messages
end if