469,300 Members | 2,255 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,300 developers. It's quick & easy.

MSCAL.Calendar.7 Default Date

JamesDC
66
Hey all,

How do I set the default date of my MSCAL.Calendar.7 calendar to today's date? I have it on one of my forms so that an employee can click on a given date and bring up the records form there. I just want the data to automatically be today's date, instead of having to click the desired date (which in almost all cases will be the current day's date).

Thanks in advance,

James
Feb 12 '07 #1
21 19926
Michael R
176 100+
Hey all,

How do I set the default date of my MSCAL.Calendar.7 calendar to today's date? I have it on one of my forms so that an employee can click on a given date and bring up the records form there. I just want the data to automatically be today's date, instead of having to click the desired date (which in almost all cases will be the current day's date).

Thanks in advance,

James
You can add this to form's on open event, Calendar1 being your MSCAL.Calendar.7 name property value:

Me.Calendar1.Value = Date
Feb 12 '07 #2
JamesDC
66
I have the form's on Open event set as Restore. How do I set multiple commands to this event? Such as the calendar update command?
Feb 12 '07 #3
Michael R
176 100+
I have the form's on Open event set as Restore. How do I set multiple commands to this event? Such as the calendar update command?
Right-click on the square in the upper left corner of the form and click 'propreties'. A box should open with the title "Form". Go to event tab, click on the On Open event, and there will be appear a "..." button on the left. Click on it, and add the code between those lines -
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
right here
Expand|Select|Wrap|Line Numbers
  1. End Sub
If "Restore" was written on that line from where you pressed "..." that was probably a macro, so you should add this line:
DoCmd.RunMacro "Restore" to the code I gave you.

Close the VB window and view your form.
Feb 12 '07 #4
ADezii
8,800 Expert 8TB
Hey all,

How do I set the default date of my MSCAL.Calendar.7 calendar to today's date? I have it on one of my forms so that an employee can click on a given date and bring up the records form there. I just want the data to automatically be today's date, instead of having to click the desired date (which in almost all cases will be the current day's date).

Thanks in advance,

James
As previously indicated, assuming your Calendar Name is Calendar1 then place this code in the Form's Load Event - not Open:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   Me![Calendar1].Value = Date 
  3. End Sub
Feb 12 '07 #5
Michael R
176 100+
As previously indicated, assuming your Calendar Name is Calendar1 then place this code in the Form's Load Event - not Open:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.   Me![Calendar1].Value = Date 
  3. End Sub
Also, I forgot to mention, choose 'code builder' while pressing the "..." button from On Open event line in the propreties box.
Feb 12 '07 #6
JamesDC
66
THanks for the help so far,

I'm running into problems with the Date command. The person who created the database used Date as the name of a field in the database which makes the Date command in VB useless. Is there another way around this date issue? I've tried using Now(), but it causes an error that requires debugging, which I don't know how to fix :(

Also, is there a problem with having the calendar named Calendar? I'm not sure if that is also a command somewhere.
Feb 12 '07 #7
ADezii
8,800 Expert 8TB
THanks for the help so far,

I'm running into problems with the Date command. The person who created the database used Date as the name of a field in the database which makes the Date command in VB useless. Is there another way around this date issue? I've tried using Now(), but it causes an error that requires debugging, which I don't know how to fix :(

Also, is there a problem with having the calendar named Calendar? I'm not sure if that is also a command somewhere.
__1 You should have no problem using Format(Now(), "mm/dd/yyyy") instead of Date.
__2 What is the nature of the Error caused by using Now()?
__3 Calendar is part of the Class Name defining the OLE Object as in MSCAL.Calendar.7. Simply rename your Calendar Control to avoid possible Errors.
Feb 12 '07 #8
JamesDC
66
I have in the On Load event this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Me![Calendar1].Value = Format(Now(), "mm/dd/yyyy")
  3. End Sub
  4.  
And when I run my form i get this error:

Run-time error '2448':
You can't assign a value to this object.

I've changed the name of Calendar to Calendar1 so as to avoid the problems with its name, but I still get the error.

When I hit debug on the error it highlights the Me! line of code.

Any ideas on this?
Feb 12 '07 #9
Michael R
176 100+
I have in the On Load event this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2.     Me![Calendar1].Value = Format(Now(), "mm/dd/yyyy")
  3. End Sub
  4.  
And when I run my form i get this error:

Run-time error '2448':
You can't assign a value to this object.

I've changed the name of Calendar to Calendar1 so as to avoid the problems with its name, but I still get the error.

When I hit debug on the error it highlights the Me! line of code.

Any ideas on this?
As in VBA you write this: "me." does a dropdown menu opens with the different objects of me.? If yes look for calendar there and add to it ".value".
Feb 12 '07 #10
JamesDC
66
When I write in Me., Calendar1 appears in the drop down menu. However I still get the same error when I write it manually.
Feb 12 '07 #11
NeoPa
32,173 Expert Mod 16PB
Try leaving off the .Value part.
Also, Date() should always be available, you may have problems accessing the field as Date on its own though. Use a specific reference (Table.Date) or simply [Date] should work for the field.
Feb 12 '07 #12
NeoPa
32,173 Expert Mod 16PB
...Also, have you tried seeing if you can set the Default property of the Calendar control to :
Expand|Select|Wrap|Line Numbers
  1. =Date()
Feb 12 '07 #13
JamesDC
66
Leaving off the .Value part creates this error:
Run-time error '-2147352567 (80020009)':
You can't assign a value to this object.

When I type in Date() into VB, it automatically removes the brackets from the end, I'm not sure if these means something.

And as far as a default value for the calendar, the only field that would suggest this is the Value property. I tried using Date() and Now() there but it would just erase the box. It needs to be a single date entered into it.
Feb 13 '07 #14
NeoPa
32,173 Expert Mod 16PB
Sorry James, I was just fishing really. I don't use the Calendar control myself much (At all).
The Date() thing makes sense, VBA doesn't like empty () by a function. I use it whenever allowed to document that it's a function I'm dealing with.
Feb 13 '07 #15
JamesDC
66
No problem, they were good suggestions, it's a shame nothing has worked so far.

I've found references to the on Open or on Load codes that were previously mentioned by Michael R and ADezii elsewhere on the internet, but I still can't get past the error that pops up.

Is there an issue about commands in different versions or Access? I'm using the 2003 version.

Also, in the preferences for the calender are areas for Year, Month, and Day. These seem to feed into the box Value that I tried to change already. I tried putting in something like =Date() or =Now() into these sections and I get the message:
VB can't convert the data type of one of the arguments you entered.
You tried to run a VB procedure that executes a method or sets a property of an object.
Check the document's documentation for information on the properties and methods it makes available for Automation operations.

I don't know what it means by the last line for automation.

Any ideas?
Feb 13 '07 #16
JamesDC
66
I've now tried to use in the VB code different variations of:
Expand|Select|Wrap|Line Numbers
  1. Me.Calendar1.Month = Date
  2. Me.Calendar1.Month = Now
  3. Me.Calendar1.Month = Format(Date,"mm")
  4.  
Doing so for Day, Month, and Year, which appear to be the fields that feed into the Value field for the calendar. When I run these nothing happens. There is no error, but the calendar is not effected in any way that I can determine. As soon as I change the .Month to .Value I get the errors again, which says to me there is something wrong with the .Value command... but that's just me.
Feb 13 '07 #17
JamesDC
66
Well, I figured it out, after trying everything :D Here's what I did:

In the event area: 'On Current' I put in the following Event Procedure:

Expand|Select|Wrap|Line Numbers
  1.     Me.Calendar1.Day = Format(Now(), "dd")
  2.     Me.Calendar1.Month = Format(Now(), "mm")
  3.     Me.Calendar1.Year = Format(Now(), "yyyy")
  4.  
My Date() command still doesn't work, so I just formatted the Now() command. I believe .Value will work here too, without throwing the error.

Thanks for the help :)
Feb 13 '07 #18
NeoPa
32,173 Expert Mod 16PB
No problem, they were good suggestions, it's a shame nothing has worked so far.

I've found references to the on Open or on Load codes that were previously mentioned by Michael R and ADezii elsewhere on the internet, but I still can't get past the error that pops up.

Is there an issue about commands in different versions or Access? I'm using the 2003 version.

Also, in the preferences for the calender are areas for Year, Month, and Day. These seem to feed into the box Value that I tried to change already. I tried putting in something like =Date() or =Now() into these sections and I get the message:
VB can't convert the data type of one of the arguments you entered.
You tried to run a VB procedure that executes a method or sets a property of an object.
Check the document's documentation for information on the properties and methods it makes available for Automation operations.

I don't know what it means by the last line for automation.

Any ideas?
I can't help much here I'm afraid as I know very little about this control.
You could consider learning more about the control itself (Use Alt-F11 to switch to the VBA window then F2 to open the object browser window). Navigate to the control and see what type of value the .Value property uses.
I can also explain that Automation usually refers to control of an application from outside. EG. Controlling MS Access from code running within Excel.
Feb 13 '07 #19
JamesDC
66
Wow, I didn't know about the F2 menu in VB (I only started using VB 2 weeks ago...)

Apparently .Value is defined as a Variant. Day, Month, and Year are defined as integers. What a Variant is, I do no, I assume something to do with the formatting of a date...
Feb 13 '07 #20
NeoPa
32,173 Expert Mod 16PB
Just created - as if for you ;)
(VBA Data Types)
Feb 13 '07 #21
in the SOURCE CONTROL of the CALENDAR box propierties
type =Date()
Dec 19 '11 #22

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by cg_news | last post: by
reply views Thread by Tim Graichen | last post: by
reply views Thread by Michael Holberton | last post: by
8 posts views Thread by Shyguy | last post: by
1 post views Thread by jim_parent_804 | last post: by
2 posts views Thread by Mariano Padilla | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.