AutoFill a date

Snarg

New member
Local time
Yesterday, 16:39
Joined
Jan 21, 2007
Messages
8
Greetings. This is my first forray into databses so please, bear with me. For being a first timer I would like to think I have done fairly well so far, on my own. I have run into a problem though that I can not seem to solve. I have used search quite extensivly however I don't seem to be asking the correct questions. I'll explain what I am attempting to do as clearly as possbile. I'll also include a screenshot in the hopes that that makes it easier to understand.

There is a large ammount of equipment we perform maintainence on. Currently all of our records are done the old fashioned way, on paper. With our current tracking system (none, really) it is quite possible to visit the same equipment a number of times in a week and not even realize it. Multiple calls for minor maintainence may be indicitive of a larger problem. So, the database will track what equipment we have gone out to, what it was for and when we went. This is in order to track any trends.

I hope all of that made sense. With all that said, here is what I am trying to do. I have two forms: A main form and a sub-form. The sub-form contains the date we went out and the maintainence performed. I have the date set up as a medium date with an input mask thing like this: 00\->L<LL\-00;0;_

What I would like to have happen is when someone clicks in the date field it automaticly fills in todays date. I have already tried messing with the On Click thing but it is not working. The best I have gotten so far is to have a date inserted (of the wrong format) every time the main form is opened up creating a new record in the sub-form every time.

Attached is a screenshot of the database. I am well aware that it is probably the ugliest database in existance :) Any help would be greatly appreciated.

Edit: I am using Access 2003
 

Attachments

  • ugly database.jpg
    ugly database.jpg
    30.8 KB · Views: 125
Last edited:
Put the following code in OnClick event of the control on the subform. I have called it txtDateOut. You have the its label as Date, The name of the control should NOT be named Date ... it is a reserved word in Access.


Me.txtDateOut = Date
 
ansentry said:
Put the following code in OnClick event of the control on the subform. I have called it txtDateOut. You have the its label as Date, The name of the control should NOT be named Date ... it is a reserved word in Access.
Thank you for the quick reply. I have tried as you suggested however I am having issues. I managed to rename the table field to MaintDate and I have also managed to get the form to recognize the newley renamed field (that is a whole 'nother story :). However, I can not get the code to work. I have tried it exactly as you posted even though I am sure that will not work in my situation. I have then tried more then a few variations of the code including using the new name of MaintDate. Below is a screenshot of the code and where I placed it and a screenshot of the error. Once again, thank you for the help.
 

Attachments

  • code.jpg
    code.jpg
    26.5 KB · Views: 124
  • error.jpg
    error.jpg
    17.3 KB · Views: 121
Click in the 'On Click' field. Click the button to the right with the 3 dots. Select 'Code Builder.' This will open the code builder and you will find something to this effect:

Code:
Private MaintDate_OnClick()

End Sub

Put the code between these lines to read:

Code:
Private MaintDate_OnClick()
me.MaintDate = date()
End Sub
 
Yes! I finaly got it! I had to change the data type in the table to text and remove the input masks to get it to work. Thank you very much to ansentry and ColeChaW. I hope you don't mind me bugging you later on with more of my inane questions.
 
Rich said:
You shouldn't store a date field as a text data type
Ok. I set the table field back to date/time. I guess it was the input mask that was screwing it up.
 

Users who are viewing this thread

Back
Top Bottom