Year Function in a report

R

renvik

Hi folks -
I have the following piece of code:

Private Sub Report_Activate()
Dim strRoll As String, numYear As Integer
If Month(Date) >= 1 And Month(Date) <= 12 Then
strRoll = Me!RollNum
numYear = Year(Date)
Me!Session = Year(Date)
End If

The problem is that while the Month(Date) works fine but Year(Date) gives
the error 'object not in collection'!
How can this be? Or am I missing something?

Thank you.
KKB
 
J

John Vinson

Hi folks -
I have the following piece of code:

Private Sub Report_Activate()
Dim strRoll As String, numYear As Integer
If Month(Date) >= 1 And Month(Date) <= 12 Then

ummm... that IF statement will always without exception be true. Every
date is part of some month, and the Month() function returns an
integer which will always be >= 1 and <= 12. What's the function of
this IF?
strRoll = Me!RollNum
numYear = Year(Date)
Me!Session = Year(Date)
End If

The problem is that while the Month(Date) works fine but Year(Date) gives
the error 'object not in collection'!

By Date are you referring to the builtin Date() function, which
returns the current date? Or to the name of a control or field on your
Report? Since Date is a reserved word, it's wise to avoid using it as
a fieldname for just this purpose. Change it to SessionDate perhaps!

This might also be a known bug: the very common References bug.
Open any module in design view, or open the VBA editor by typing
Ctrl-G. Select Tools... References from the menu. One of the
..DLL files required by Access will probably be marked
MISSING. Uncheck it, recheck it, close and open Access.

If none are MISSING, check any reference; close and open
Access; then uncheck it again. This will force Access to
relink the libraries.
 

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