RecordCount

J

JamesJ

I'm using the following code to the return the number of records
displayed on a Split Form 'cause I can't get the Split Form's
Navigation buttons to work properly.
Well this doesn't seem to work either.
It displays only the caption of the label (lblCount).
The code works fine on a single form using the same Record Source.

Dim intNewrec As Integer

intNewrec = IsNull(Me.ProductID)

If intNewrec Then

lblCount.Caption = "***New Record***"

Else

With Me.RecordsetClone
.MoveLast
lblCount.Caption = .RecordCount & " Items"
End With

End If

Any help will be appreciated,
James
 
D

Dennis

Well, first I'd use a DCount statement to count the records.

Second, why are tyou trying to change a LABEL control? Create a LOCKED
textbox control and fill that with whatever text you choose. Labels are
designed to be static, while textboxes are used for dynamic data.
 
J

JamesJ

Don't really know where to start with the DCount and the unbound text box.
Looked at help for DCount but really didn't see an example for what I
want to accomplish. More help will be appreciated.

James
 
D

Dale Fye

James,

I think I would do what you are trying to do like:

If me.NewRecord then
lblCount.Caption = "*** New Record ***"
Else
lblCount = me.recordsetclone.recordcount
end if

When you use the recordsetclone, you can use its recordcount property
directly, without first moving to the last record.

HTH
Dale
 
J

JamesJ

Work ok, thanks.

James

Dale Fye said:
James,

I think I would do what you are trying to do like:

If me.NewRecord then
lblCount.Caption = "*** New Record ***"
Else
lblCount = me.recordsetclone.recordcount
end if

When you use the recordsetclone, you can use its recordcount property
directly, without first moving to the last record.

HTH
Dale
 
J

JamesJ

Sorry, spoke too soon. It seemed to work last night but when
I filter the records the textbox doesn;t refrlect the new total in the
recordset.
I have the following in the OnCurrent of the form:

If Me.NewRecord Then
txtCount = "*** New Record ***"
Else
txtCount = Me.RecordsetClone.RecordCount
End If

James
 
D

Dale Fye

James,

When you filter the recordset, is the pointer going to a new record, or does
it remain on the current record. If it stays on the current record, then try
moving to another record, what happens to your count figure.

My guess is that in the same routine that you "filter" the recordset, you
will have to call the Current event of the form to force that code to run
again.

Dale
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 
J

JamesJ

It appears calling Form_Current did the trick. Although when
I load the form I need to set the focus to a field in order for txtCount
to display the number of items.

Thanks,
James
 
D

Dale Fye

James,

If the form is bound to a datasource, the Current event should fire
automatically when the form is loaded.
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 
J

JamesJ

It is bound to an sql but the OnCurrent isn't triggered when
the form opens
This is a Split Form, if that matters.

James
 
D

Dale Fye

Are you running 2007?

JamesJ said:
It is bound to an sql but the OnCurrent isn't triggered when
the form opens
This is a Split Form, if that matters.

James
 
D

Dale Fye

Cannot help you much more then, I don't have 2007.

However, my first thought is the in the Open event, you could set the focus
to a control in the portion of the form that has your data in it.

Dale
 

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