Dear all,
I have a form, where I removed the “default record counter at the bottom of the page” and added a custom made (the code is shown below)! But however I have a problem now, because when I use my search, and if there was a mistake in search I get a debug message “Run time error 3021: No current record. “ and it marks my “.MoveFirst” part of my custom made record counter. I would like to bypass the debug thing and just leave message box that there is no record!
Any clue how to do this!
Thanks in advance!
CUSTOM MADE record counter (added a unbounded text box with code on current event) :
Private Sub Form_Current()
'Show the result of the record count in the text box (txtRecordNo)
Dim lngCount As Long
Set rst = Me.RecordsetClone
With rst
.MoveFirst
.MoveLast
lngCount = .RecordCount
End With
Me.txtRecordNo = "Customer " & Me.CurrentRecord & " of " & lngCount
End Sub
SEARCH CODE :
Private Sub cmdSearch_Click()
If Len(cboSearchField) = 0 Or IsNull(cboSearchField) = True Then
MsgBox "You must select a field to search."
ElseIf Len(txtSearchString) = 0 Or IsNull(txtSearchString) = True Then
MsgBox "You must enter a search string."
Else
'Generate search criteria
GCriteria = cboSearchField.Value & " LIKE '*" & txtSearchString & "*'"
'Filter frmCustomers based on search criteria
Form_frmSales.RecordSource = "select * from qry_filter_current_user where " & GCriteria
Form_frmSales.Caption = "Customers (" & cboSearchField.Value & " contains '*" & txtSearchString & "*')"
'Close frmSearch
DoCmd.Close acForm, "frmSearch"
MsgBox "Results have been filtered."
End If
End Sub