Code for putting current date into a field.

dreamspy

Registered User.
Local time
Yesterday, 23:51
Joined
Jul 13, 2006
Messages
18
Hi

Have a question regarding VBA script in Access.

Now a quick description of the cituation.

In a form, I have a check box, and a text box next to it (whick refers to a specific field in a table). When the user marks the check box, he fills in the date in the text box (the date is the current date).

Can anybody give me a hint on how this would be done in code? So always when somebody clicks the check box, access would put the current date in the text box, but only if there is no date there before. Basicly recording the first time when the box was checked.

btw... anybody know of a good place to find beginniers information for VBA in Access?


regards
Frímann Kjerúlf
 
Actually you don't need code at all.

Simply set the textbox's default value (in Data tab on property sheet) to Date().
 
Banana: that only works when the record is created. In this case, the record is created when the item is expected. Then the date is filled in when the item arrives. So when the item arrives, the check box is marked, and the date is typed in. What I want to to do is make the date be filled in automaticaly.

I'we found out the code for putting in the date everytime the box is checked. (quite easy actualy)

But I am having hard time making access only fill in the date, when there is no date there before. What I'we done works, but is rather unprofessional:

Private Sub Master__Item_arrived_Click()
If Me.Item_arrived_date > 1 / 1 / 2000 Then
Else
Me.Item_arrived_date = Date
End If
End Sub


What i would like to do is make the if statement check if there is "anything" in the date field.
 
But let's say I don't want the text box on the form. I just want to record the date to a field in some table. Anybody know how to do that in code?
 
This should be in AfterUpdate, not on Click event.

What you would want is something like this

Code:
If Not IsNull(Me.Item_arrived_date) Then Me.Item_arrived_date = Date
 
That's working like a gem. Thanks :)

But I have another question. If the date field should not be visible on the form (both in form view and datasheet view). How would I go about this? Making the form "not visible" doesn't work because it's always visible in datasheet view.
 
You should be able to set column width to zero in datasheet? I've never used datasheet, but for form, I simply set the property visible = False.
 

Users who are viewing this thread

Back
Top Bottom