I'm trying to show the number of records return from a filter in a text box. Currentl it works fo the complete record source (ie, it shows 1 of 101 records etc.) What i'm trying to do is disaply the number of filtered items returns (ie. 1 of 17 etc).
I have included the code i am trying. Currently i get a runtime error 3075 (syntax error in query expresion) on this line:
Private Sub search_company_Change()Dim SQL As StringDim recClone As ObjectMe!lbCompanies.RowSource = "SELECT * FROM tbl_Contacts Where [company_name] Like '" & Me.search_company.Text & "*' ORDER BY [company_name] ASC;"SQL = " SELECT * FROM tbl_Contacts Where [company_name] Like '" & Me.search_company.Text & "*' ORDER BY [company_name] ASC;"Form.RecordSource = SQLSet recClone = Me.RecordsetClone' Check to see if there are no recordsIf recClone.RecordCount = 0 Then cmdNext.enabled = False cmdPrevious.enabled = False cmdFirst.enabled = False cmdLast.enabled = FalseElseMe![RecordCount] = "Contact " & (recClone.AbsolutePosition + 1) & " of " & _ DCount("company_id", "tbl_contacts", SQL)recClone.CloseDoCmd.RunCommand acCmdRefreshPageEnd IfEnd Sub
Private Sub search_company_Change()Dim SQL As String, sWhere as stringDim recClone As ObjectMe!lbCompanies.RowSource = "SELECT * FROM tbl_Contacts Where [company_name] Like '" & Me.search_company.Text & "*' ORDER BY [company_name] ASC;"SQL = " SELECT * FROM tbl_Contacts Where [company_name] Like '" & Me.search_company.Text & "*' ORDER BY [company_name] ASC;"Form.RecordSource = SQLsWhere= "[company_name] Like '" & Me.search_company.Text & "*'"Set recClone = Me.RecordsetClone' Check to see if there are no recordsIf recClone.RecordCount = 0 Then cmdNext.enabled = False cmdPrevious.enabled = False cmdFirst.enabled = False cmdLast.enabled = FalseElseMe![RecordCount] = "Contact " & (recClone.AbsolutePosition + 1) & " of " & _ DCount("company_id", "tbl_contacts", sWhere)recClone.CloseDoCmd.RunCommand acCmdRefreshPageEnd IfEnd Sub
That worked.
The only problem now is when the user clicks 'next record' on my navigation buttons the number of records returned from the filter goes back to the full amount even though they can only navigate to the number of records returned from the filter.
How can i keep the number of item displyed as they scroll through the filtered records?
My Next Button is:
Public Function navToNext(frm As Object)On Error GoTo Err_navToNextDoCmd.GoToRecord acDataForm, frm.Name, acNextExit_navToNext: Exit FunctionErr_navToNext: MsgBox Err.description Resume Exit_navToNextEnd Function
Open in new window