M
moshi
Guest
Hi
I have a main form and a subform. On my main form. I have a text box which will display the number of records returned from the subform. The name of the text field on main form is numberRecords.
On my main form there are a number of text fields which users can type in. Based on the information entered eg search for surname in database of people called "Smith" the results will get filtered and displayed on the subform.
I want to display the number of records returned in the subform on a text box on the main form. For example if there were 5 people in the database with the surname of Smith there will be 5 records displayed and it will display on the main form in the textbox named numberRecords the number 5.
To do this I have used an expression in my code on my subform on the "On Current" event procedure using this code...
Dim rst As Recordset
Set rst = Me.RecordsetClone
If (rst.EOF And rst.BOF) Then
[Forms]![MainForm]![numberRecords] = 0
MsgBox "No records found"
Else
rst.MoveLast
[Forms]![MainForm]![numberRecords] = rst.RecordCount
End If
The problem is that when no records are returned (that is all the navigation button on the subform is greyed out (ie not pressable)
it doesn't seem to display the number of records as 0 it remains the same as the previous results. For example, if I search main form Smith and it displays 5 records and then the next search I do has 0 records it just displays 5 records. However if there are records returned eg displays 5 records, then next record is 3 then it will display 3.
I have also tried this as well
Dim numRec As Recordset
Set numRec = Me.RecordsetClone
numRec.MoveLast
If numRec.RecordCount > 0 Then
[Forms]![MainForm]![numberRecords] = numRec.RecordCount
Else
[Forms]![MainForm]![numberRecords] = 0
MsgBox "No records to Display"
End If
but it still has same problem that is doesn't seem to show 0 records or recognise it.
Does anyone know what the problem is or how I can fix it?
I have a main form and a subform. On my main form. I have a text box which will display the number of records returned from the subform. The name of the text field on main form is numberRecords.
On my main form there are a number of text fields which users can type in. Based on the information entered eg search for surname in database of people called "Smith" the results will get filtered and displayed on the subform.
I want to display the number of records returned in the subform on a text box on the main form. For example if there were 5 people in the database with the surname of Smith there will be 5 records displayed and it will display on the main form in the textbox named numberRecords the number 5.
To do this I have used an expression in my code on my subform on the "On Current" event procedure using this code...
Dim rst As Recordset
Set rst = Me.RecordsetClone
If (rst.EOF And rst.BOF) Then
[Forms]![MainForm]![numberRecords] = 0
MsgBox "No records found"
Else
rst.MoveLast
[Forms]![MainForm]![numberRecords] = rst.RecordCount
End If
The problem is that when no records are returned (that is all the navigation button on the subform is greyed out (ie not pressable)
it doesn't seem to display the number of records as 0 it remains the same as the previous results. For example, if I search main form Smith and it displays 5 records and then the next search I do has 0 records it just displays 5 records. However if there are records returned eg displays 5 records, then next record is 3 then it will display 3.
I have also tried this as well
Dim numRec As Recordset
Set numRec = Me.RecordsetClone
numRec.MoveLast
If numRec.RecordCount > 0 Then
[Forms]![MainForm]![numberRecords] = numRec.RecordCount
Else
[Forms]![MainForm]![numberRecords] = 0
MsgBox "No records to Display"
End If
but it still has same problem that is doesn't seem to show 0 records or recognise it.
Does anyone know what the problem is or how I can fix it?
