Getting day of month (1st through 31st)

home70

Registered User.
Local time
Today, 03:02
Joined
Jul 10, 2006
Messages
72
For a field on a report, I'm trying to use an If/Then statement to set the Control Source depending on the day of the month. I need one Control Source for days 1-14 and another for 15-31. To do this I put this into the report's open event:
If (Day(date) < 15) Then
here are the control source statements and the Else statement.
End If

On one report this works fine, but after I copy and paste the code into another report, when I try to open the report it gives the error:
Runtime Error 2427
You entered an expression that has no value.
After I click the debug button, it highlights the If/Then line:
If (Day(date) < 15) Then

I tried setting the problem report to the same query that the other report uses (they have many of the same fields and their queries are very similar) but it still gives the error. I made sure that I'm putting it into the report's Open section. For testing, I tried disabling the controlsource setting line and just using a command that changes the fore color, but same results.

**The word "date" in the If/Then line above is not a field on the report, it's the Access variable for the date. I tried to make the line say:
If (Day(date()) < 15) Then
but as soon as my cursor leaves the line it changes back to this:
If (Day(date) < 15) Then

Anyone know what would be causing this?
 
I think you simply need to remove the parens ( and the date thing is normal...)

if Day(date) < 15 then
xxxx
end if

???
 
Thanks but that didn't fix it.
 
Hum...

Just double checked and the following code worked on my machine:

If Day(Date) > 15 Then
MsgBox "GT 15"
End If

Do a new form with one button that executes this code and see if it works.
 
Yes it does work on another report I have. I can't figure out why it won't work on this one.
 
Hum... Put in a break point and see what 'date' returns in the immediate window at that point.
 
Can you tell me how can I do that? I don't know anything about break points. Thanks.
 
Open help (or press F1 key), click on index tab, type in 'breakpoint', RTM

good luck, Help can be your friend...:D :D :D

Also, is the verable date created by you. It is usually a reserved word....maybe throw date() into a verable and use that... Cheap and nasty but works.
 
Last edited:
I got this fixed several days ago and I believe that the problem was that the If/Then statement was used for field formatting and field enabling/disabling statements. I moved the whole bunch from the Report Open section to the Detail Format section and it started working.
 

Users who are viewing this thread

Back
Top Bottom