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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calendar still won't default to current date

Status
Not open for further replies.

billcam

Technical User
Jun 7, 2001
29
0
0
US
My calendar works fine except for defaulting to today's date. I have tried the recommendations from this board but still am having trouble. If I set the control source to current date, it defaults fine but cannot be changed. I have tried using the onload and on open events for the form and setting cal.value=date() but nothing happens. I have tried the on focus event but nothing happened. I must be missing something simple, like a brain.
 
needs to look like this with the me keyword

replace calendar1 with what ever you named your calendar

Private Sub Form_Load()
Me.Calendar01.value = Date
End Sub
 
billcam,
There are several ways to accomplish what you are doing. But it depends on how you want it done..
How are you setting the source date? ... How is the database setup? ... is this a text box that you have in a form? Do you have it setup as an event behind the text box that is linked to the date field in the table ... and the event is setup in code like...

Keep in mind that the on enter might not be the best one... maybe before update would be better for you.....

Private Sub Date_Enter()
NameofTextBoxdate = Date()

End Sub
(I didn't test this out... so I'm not sure if it will default back to todays date everytime you open the form, or just for new, unedited, forms. I think it should leave edited values alone.)

That will make it so that in the form when you open the form the value placed into that box will always be the current date.. you shouldn't have any problem changing that value to a new value.

Also, you can make it a default value in the design view of the table you are storing these records. Just set the field's default value to Date() ... I hope I've helped atleast a little bit to get you moving in the right direction... Goodluck

PS - I'm positive now that i Think about it that before update would be a much better place to put that code... so dont do it on enter.. place it by before update
-Happen609
Wasting more of your valuable time...
 
oh ... whoops .. didn't read the entire first post well enough... sorry, you probably dont even need what I posted.. Goodluck anyways... -Happen609
Wasting more of your valuable time...
 
It still does not do anything. Here is the code for the on load event of the form. It defaults to the date on the first record.
Option Compare Database

Private Sub ActiveXCtl128_Click()
[Date] = [ActiveXCtl128].[Value]
End Sub

Private Sub ActiveXCtl128_Updated(Code As Integer)

End Sub

Private Sub Command129_Click()
On Error GoTo Err_Command129_Click


DoCmd.GoToRecord , , acNewRec

Exit_Command129_Click:
Exit Sub

Err_Command129_Click:
MsgBox Err.Description
Resume Exit_Command129_Click

End Sub
Private Sub Command130_Click()
On Error GoTo Err_Command130_Click


DoCmd.Close

Exit_Command130_Click:
Exit Sub

Err_Command130_Click:
MsgBox Err.Description
Resume Exit_Command130_Click

End Sub

Private Sub Form_Load()
Me.[ActiveXCtl128].[Value] = Date
End Sub
 
I don't know if this applies to your case or not, but I have a sample db with a special calendar for I have that allows you to double click a date field and have the calendar form open up. If the date field has a date, the calendar goes to the date, if it's blank, the calendar goes to the current date. The user can then select a date from the calendar control and click select which puts it back into the control. There is only one form to put in your db and when you call it you supply openargs to it so it knows what control to update for you.

If you're interested let me know your email address and I can send it to you.

Joe Miller
joe.miller@flotech.net
 
Is the field named date? ... for instance is the field that you are storing the date into named "date" ...
so when you tell it to make the field date it reverts to the first record of that field as the date.

Private Sub Form_Load()
Me.[ActiveXCtl128].[Value] = Date
End Sub
^^^
is that the name of a field in a table?
If so try changing it to CalDate or something like that... and then just change the control sources that need to be changed based on that.. make sure that you use Date() .. not just date... I think Access is picky about things like that.
I know that there are people on this forum who can just blow my knowledge of access away.. I hope they respond to you as well.. Goodluck .. -Happen609
Wasting more of your valuable time...
 
I finally got it to work by using now() in the onload event and changing my date format to general instead of short date. I don't understand why date won't work except that it wont keep the () after date and it will after now like it does not recognize date as a keyword.
 
Bill,

I have exactly the same problem and, like you, I substituted the NOW function for the Date function. The problem only arose when I upgraded from '97 to '2000.
However, I have recently realised that this is NOT the way to do things as I recently wrote a query to find records that had a particular date and got absolutely nothing, although I knew records existed? I had to use the wildcard * after the date, e.g. 'Like 20/04/02*' before it would find them, as by using the NOW function each record is different.

I'm pretty sure that this has something to do with DAO/ADO and is easily remedied by adding a particular Library to the database but, unfortunately, my experience does not extend that far I'm afraid.

So, any help from the more experienced Access users/developers would be most welcomed?!

Many thanks,

Adrian
 
Hi billcam,
If you wnat the calendar control to merely default to todays' date when the form opens, try the following code in the From Load event:

Me.Calendar1=Date

Let us know what happens.
 
tlv,

Thanks, but we know the 'date' funtion. Our problem is that the 'date' function is no longer recognized? Only the 'now' function seems to work?

Regards,

Adrian
 
Hi Adrian,
What do you mean when you say Date function is no longer recognized? If it is some problem with your Access, why don't try to uninstall Access completely ( run time and everything )and then re-install it? See if the date function works. I have also used a couple of Calendar controls in my project and I use Date to set it to today's date and it is working fine. I am using Access 2000.

Hope you are able to solve your problem. Let us know what happens.

Regards,
tlv
 
Hi Adrian,
if your now() function works, try the following:

Me.Calendar1= CDate(Left(Now(),10))

This also will work provided you change the length in the Left function as per your system settings. I have used the DD/MM/YYYY for date in my system. So I retrieve the 10 leftmost characters.

Try this one out and let me know.

Regards,
tlv
 
Hi all, I've been stuck on this problem for ages too. I found this in another forum. I have used it in Access 2000 and 2002 to default a calendar to today's date when the form opens and it works. I don't know VB so this simple solution was excellent. Just replace NameOfCalendar with yours.

Private Sub Form_Load()
NameOfCalendar.Today

End Sub

 
I hope this will help. I had a similar issue which was driving me nuts. I wanted the calendar to default to either (a) today's date if the date field of my table was null (empty), or (b) the value of the date field. It wasn't working but I realised I'd set the "allow edits" property of my form to false. So I did the following

form.allowedits = True
If IsNull(fldDate.value) = True then
calControl.value = Date ( no brackets and not Today)
Else
calControl.value = fldDate.value
End If
Form.Allowedits = False

I used similar code on my custom record navigation button so that the calendar would change to reflect either the current record's date field or today's date. It works fine now. I'm using Access 2000.
 
I don't know if was imagining things but one thing that helped when I had problems some time ago with the calendar control was to delete it then replace it with an identically named calendar control. Some code I'd written had passed a null value to it and it seemed to get stuck on that null value no matter what.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top