View Full Version : detect list box value
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
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.
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).
duh!!!!!!!!!!!!!!!!!! i'm trying to figure out how it can detect the value without clicking in the list box-THE VALUE IS THERE!
Try
MsgBox Me.ListBoxName.RowSource
where ListBoxName is the actual name of your List box.
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
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
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.