Db 'Can't Find ' Existing Field

J

JamesJ

Hi. I'm using the following code on the OnCurrent of the form
to return the number of rows being returned in my continuous form:

In the General section of the module:

Dim frm As Form
------------------------------------------------------
Public Function RecCount()

Dim intCount As Integer
Set frm = Screen.ActiveForm

If frm.Recordset.RecordCount = 0 Then

frm!lblCount.Caption = "0 Item(s)"

Else

intCount = frm.Recordset.RecordCount
frm!lblCount.Caption = intCount & " Item(s)"

End If

End Function

The code works fine as a form function but not in a module.
I get the following Error:

Run-time error '2465':

MyDb can't find the field lblCount referred to in your expression.

The field is a label and is named lblCount.

Any help will be appreciated.

Thanks and Happy Thanksgiving!
James
 
T

tina

i couldn't get anything to work using Screen.ActiveForm. but assuming that
every form that calls the function contains a label object named lblCount,
the following should work in a public module, as

Public Function RecCount()

On Error Resume Next

Dim intCount As Integer

With CodeContextObject
.RecordsetClone.MoveLast
intCount = .RecordsetClone.RecordCount
If intCount = 1 Then
!lblCount.Caption = "1 Item"
Else
!lblCount.Caption = intCount & " Items"
End If
End With

End Function

hth
 
J

JamesJ

I altered the code and I'm not sure why this works but..
I needed to check for no records so when the continuous form
displays only the new record the lblCount caption displays
0 Item(s). I was banging my head trying to check for no
records and I apparently don't need to.
All is fine now. Thanks

On Error Resume Next

Dim intCount As Integer

With CodeContextObject
intCount = .RecordsetClone.RecordCount
!lblCount.Caption = intCount & " Items"
End With

Thanks again,
James
 
T

tina

you're welcome :)


JamesJ said:
I altered the code and I'm not sure why this works but..
I needed to check for no records so when the continuous form
displays only the new record the lblCount caption displays
0 Item(s). I was banging my head trying to check for no
records and I apparently don't need to.
All is fine now. Thanks

On Error Resume Next

Dim intCount As Integer

With CodeContextObject
intCount = .RecordsetClone.RecordCount
!lblCount.Caption = intCount & " Items"
End With

Thanks again,
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