Unbound Text Box Showing Wrong Number of Records

J

JamesJ

I'm using the following code to return the number of records on a split form
in a unbound text box named txtCount:

Private Sub Form_Current()
If Me.NewRecord Then
txtCount = "0 Item(s)"
Else
txtCount = Me.RecordsetClone.RecordCount & " Item(s)"
End If
End Sub

Everthing seems to work properly with the text box returning the propr
number of records.

But when I open a form based on the same table using the following code by
clicking on the ID field:

Private Sub ContactID_Click()
If Not IsNull(Me.ContactID) Then
DoCmd.OpenForm "frmContactsEdit", OpenArgs:=Me.ContactID
Else
DoCmd.OpenForm "frmContactsEdit", , , , acFormAdd 'Open the
form on a new record
End If
End Sub

After I close frmContactsEdit txtCount the underlying form shows only 1
record even though
all records are being displayed. I know this has something to do with the
fact that I am in reality
filtering frmContactsEdit to the one record.
I have Forms!frmContacts.Requery in the OnClose of frmContactsEdit to save
any changes to records.
When I remark out the requery it's fine.
So, I need to find another way to open frmContactsEdit to the desired record
a different way or find
another way to reflect any changes I made to a record in frmContactsEdit.

Any help will be appreciated,
James
 
B

BruceM

I can't follow exactly what you are saying. What is the "underlying form"?
Is it the one with the Current event code?

You could try this before your RecordsetClone.RecordCount line:
Me.RecordsetClone.MoveLast

I would consider using the syntax Me.txtCount rather than just txtCount if
it is the name of a control. Access may be treating txtCount as a variable
of variant type rather than as a text box.
 
J

JamesJ

Adding your examples did the trick. Apparently, the first form wasn't moving
through he recordset and
in doing a requery in closing the other form caused it to show only 1 item,
I believe.

Thanks much,
James
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top