setting a default date in a field after clicking a command button

tina hayes

Registered User.
Local time
Today, 14:24
Joined
Jul 28, 2004
Messages
37
I have a new box form, which chooses to add the new box to the main form. When you click the continue button it asks if you would like to save details to the main form you say yes and the main form appears with the information on.
What I am trying to do is;
On the properties of the exit button I am choosing “on exit” and coding it so that when it is the set the value in the deposit table is default to that days date with the option of changing.
The code I adds a date in but is not “todays date”
Please help
The code I have so far is

Private Sub continue_Exit(Cancel As Integer)
Dim todaysdate As Date

Dim stDocName As String

stDocName = "Main Form"

Forms![main form]![Depositdate].SetFocus
Forms![main form]![Depositdate].Text = todaysdate

End Sub
 
tina hayes said:
Private Sub continue_Exit(Cancel As Integer)
Dim todaysdate As Date
Dim stDocName As String

stDocName = "Main Form"

Forms![main form]![Depositdate].SetFocus
Forms![main form]![Depositdate].Text = todaysdate

End Sub

I don't know why you're using the Exit event of a command button for this - the Click would be more sensible. The Exit event triggers when you leave the button.

Also, your code can be refined to:


Code:
Forms![main form]![Depositdate] = Date

If main form is the current form, you can refine it further to:

Code:
Me.Depositdate = Date
 
thankyou

mile-o-phile

many thanks it works you are star

thankyou for your time
 

Users who are viewing this thread

Back
Top Bottom