Validate Year on Report

dtaylor

Active Member
Joined
Mar 21, 2002
Messages
379
Hello All,
What I am trying to do is validate the year on opening a report.
The report contains a textbox that has function to determine the current year.

I have a form with all my reports and the user can select to view an old table or the current years. I do not want to create a report for each instance, since I have coded my form to change the report record source based on user selections.

The problem is if the user selects, say 2002, the data is from the 2002 table but the textbox is referring to the current year.

I want to validate the current year. Say the user is viewing 2002 table in 2003, textbox refers to 2003. I want to be able to change the textbox with a user selection to the correct year.

I have been playing with some code, but when I try to update the text box I get an error "Can't assign value to this object'.

Here is the code:
Private Sub Report_Open(Cancel As Integer)
If MsgBox("Is Current Year " & FiscalYear(Now()) & "?", vbYesNo) = vbYes Then
Exit Sub
Else
Me.txtFiscalYear = InputBox("What Year Then?")
End If
End Sub


I am I offbase here? How do you change an object on a report dynamically?

Thanks

Dan
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi dtaylor,

Firstly,
Me.txtFiscalYear = InputBox("What Year Then?")
should be just
txtfiscalyear =InputBox("What Year Then?")
no need for 'me'.

Secondly, you should have all this data in one table. There's no point in separating each year's data into its own table. That's what querries are for. Sometimes you have no choice, though, so sorry if that's the case.

HTH,
 
Upvote 0
Thanks for the info corticus...yea i know i should use one table but the data is just too large and most of the users couldn't cope. thats why i have broken it up, it actually has helped in other reports so i will deal with it.

i tried using your suggestion and recieved the same message. any ideas? the report is not locked

thanks

dan
 
Upvote 0
Dtaylor,

txtfiscalyear =InputBox("What Year Then?")
Should work. If you can't assign a value to this textbox you've got something else going on. Check to see if the textbox is in a subform, locked, not enabled or something that is either preventing from assigning a value to it, or you are referring to its location incorrectly.

yea i know i should use one table but the data is just too large and most of the users couldn't cope. thats why i have broken it up, it actually has helped in other reports so i will deal with it.

I still say you really should put this all in one table.
If the data is too large, that's all the more reason to put it in one table. If you don't want your users to see all the years (first of all, you usually don't want users in the actual data tables, I prefer forms), simply make querries that pull a given years data, so they only see that year. Anything you're trying to do with this data should be greatly simplified if you do this.

HTH,
 
Upvote 0

Forum statistics

Threads
1,221,514
Messages
6,160,249
Members
451,633
Latest member
sadikin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top