Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you change the default value of the monthview

Status
Not open for further replies.

MrSR

Instructor
Jan 23, 2002
39
US
i want to change the monthview1.value to be the current date
without going in and changing it everyday. i want to do it in the code. if i put in "Now" in the properties of the control itself i get an error. any suggestions
 
Try something like this

Private Sub Form_Load()
MonthView1.Month = Month(Date)
End Sub

Hope this helps. If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
no but thanks, i tried and it does not work. when the form is opened i want the month and year to be of the current date. so i needed the value property loaded when the form is loaded but it is not letting me do this does anyone have any other suggestions.
 
so basically when the form loads up the month and year will be of the current month and year
 
I am guessing then that the form stays open all the time? Is that the case? If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
no. the form is used in a template in microsoft word but im using vba. so when you create a new document using this template the form comes up. when it does come up i want the month and year to be current without having to go into the properties and change it everyday. when i put code in the form initialize i get an error.
 
thanks for staying with this one with me i appreciate your input
 
Try using this in your template code.

Private Sub Document_New()
MonthView1.Month = Month(Now)
MonthView1.Day = Day(Now)
MonthView1.Year = Year(Now)
End Sub

Let me know if that works. If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
im trying but wont let me set this in the code am i missing something else a reference or something
 
All I did was start a new Work template, then added a reference to the Microsoft Monthview control to the document. I then opened the VBA editor and add the Document_New event with the code above. I then tested it by changing the date on my computer and each time I started a new document based on the template it worked fine. Am I doing something different than you are? If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
run time error 35778
an error occurred in the call to the month view control
that is what i get. i use the component monthview, is there a reference under references i should be looking for
 
Are you actually adding the Monthview control to the document from the Controls Menu bar so that it actually appears on the document? If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
yes, i am adding it to the form from the control toolbox. so when the form comes up the control is already on there
 
In the form load event just put:
MonthView1.Value = Date
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
hi john,
ive tried that but that is when i get that error.
 
I assume that you've got thelatest service packs applied for the Common Controls. The MonthView control has suffered from a number of minor bugs, although I have to admit that the behaviour you describe does not sound like one of the known ones. For the record, I'd have given the same advice as foada and johnwm as the methods they describe work fine here...
 
i think the problem was i had the control inside of a frame, i put it on a seperate form and everything works fine
 
desperation move
try the form activate event instead of the form load
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top