Hi everyone, it's been a while
I was looking back at some codes and practicing some vba. I have this book Tips and tricks from MvPs and I decided to build a ultra-fast searching form. It took me a while to try and understand and get the code to work as I constantly stress, I truly love MS Access but am not a programmer; only aspiring
. I have this search form with a search textbox and Listbox type objects. When you type in a few characters of someone's name into the search box and press enter the list box fills with a Recordset of names from the db or table [tblEmployees]. Great! works fine.
However, I placed also another unbound txtbox field where I want it to display the number# of records that displays after the search in the ListBox. I tried placing codes and expressions in the AfterUpdate event. I just can't get this to work. What exactly am I doing wrong because this form object [frmSearch] is tied to another form and a module, which enables it to function properly. How to get the number# of records in a Recordset where the form display only one(1) in the record selectors. Note also, even when multiply records pull up after searching names the record selectors says (1). Say I search ("be") and (25) records pull into the list box. I want a textbox to display this (25). I have tried these codes...
Code:
Function FindRecordCount(strSQL As String) As Long On Error GoTo Error_Handler
Dim db As Database
Dim rstRecords As Recordset
Set db = CurrentDb
Set rstRecords = db.OpenRecordset(strSQL)
If rstRecords.EOF Then
FindRecordCount = 0
Else
rstRecords.MoveLast
FindRecordCount = rstRecords.RecordCount
End If
rstRecords.Close
db.Close
Set rstRecords = Nothing
Set db = Nothing
Exit_Here:
Exit Function
Error_Handler:
MsgBox "Error #: " & Err.Number & vbCrLf & vbCrLf & Err.Description
Resume Exit_Here
End Function
Code:
Sub RecordCountX()
Dim dbs As Database
Dim rstEmployess As Recordset
Set dbs = OpenDatabase("Database Management Practice db.accdb")
With dbs
' Show the RecordCount property after populating the
' Recordset.
rstEmployess.MoveLast
Debug.Print "Dynaset-type recordset " & _
"from tblEmployees table after MoveLast"
Debug.Print " RecordCount = " & _
rstEmployees.RecordCount
rstEmployees.Close
.Close
End With