Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please HELP.....Listbox Row 1

Status
Not open for further replies.

zishan619

Programmer
May 28, 2003
284
MX
Hi:
I have a button that would run a query based on criteria placed into the form. The results would output into a listbox. Now If the criteria goes through and brings up only the headings on the listbox I need a msgbox to pop up and say there are no records that much your criteria. How can I do this. I tried:
If isNull (Me.lstAccount.Rowsource) Then
msgbox "There are no records that match your account No. " & Me.txtAccount & "", vbInformation
Exit Sub
End If
It doesn't work. Please Help.
Thanks
Zishan
 
Have you tried:

if isnull(lstAccount.column(0,1) then
msgbox "There are no records that match your account No. " & Me.txtAccount & "", vbInformation
Exit Sub
End If


The 1 is actually the first row that is suppose to have data if you have column headings turned on.


 
Instead of If isNull (Me.lstAccount.Rowsource) Then

try using

If Me.lstAccount.ListCount = 0 Then

 
I have a similar function on one of my forms. If your query is a recordset object, something like this will work for you (in the button's Click event):

*****************************************************
Dim con As Object
Dim rs As Object
Dim stSql As String

Set con = Application.CurrentProject.Connection
Set rs = CreateObject("ADODB.Recordset")
stSql = "YOUR_QUERY_HERE"
rs.Open stSql, con, 1 ' 1 = adOpenKeyset

' If no item matches, report the error and exit
If (rs.EOF) Then
MsgBox "There are no records that match your account
No. " & Me.txtAccount, vbInformation
Exit Sub
End If
*****************************************************

Hope this helps.
 
Yep clothahump that's the better answer. Late in the day don't know what I was thinking!!!
 
Thank you JMeadows that code help...And Thanks everyone else as well.
Star for everyone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top