default value question

Access doesn't like DefDate change it to DefaultDate
 
Ok, done!
No more error message but now it's propagating a time (as opposed to a date, to be specific "00:01:36" or 30/12/1899 if I force the form to use the dd/mm/yyyy format in that field) in my date field.

The code is currently:
Code:
Private Sub Form_Open(Cancel As Integer)
    Dim DefaultDate As Date
    DefaultDate = InputBox("Enter date worked...", "Date worked")
    Me.DateOfWork.DefaultValue = DefaultDate
    DoCmd.GoToRecord , , acNewRec
End Sub
, just in case there's something else I'm missing...
 
Last edited:
30/12/1899 is a zero date.

I would do it by placing the code below in the form's events as shown

Private Sub Form_Current()

Dim Defaultdate As Date
If Me.NewRecord = False Then GoTo Fini

If MyDefaultdate = 0 Then
Defaultdate = InputBox("Please enter the default date format dd/mm/yyyy...", "Default Date")
Else: GoTo continue1
End If
MyDefaultdate = Defaultdate
continue1:
Me.strdate = MyDefaultdate 'strdate is the control name in the Form

Fini:
End Sub

Private Sub Form_Open(Cancel As Integer)
MyDefaultdate = 0
End Sub


and defining the following variant in a module

Public MyDefaultdate As Date

The default date will be asked for the first time a user accesses a new record and remain until the form is closed.

Brian
 
Thanks, Brian, I'll give that a try too...

And thanks to everyone, for the help, suggestions and PATIENCE.
 
I would recommend you using an error handler in your sub because consider that users might input a string of characters by mistake rather than a date.
 
maxmangion said:
I would recommend you using an error handler in your sub because consider that users might input a string of characters by mistake rather than a date.

That's why I prefer to input dates in a formatted field on a form then even errors such as 29/02/2005 are easily caught, but reading the thread I think Lac wanted to go a particular way as he trusts the single user, ie his boss!

Brian
 
ok Max you tweaked my conscience so finding myself with a bit of time on my hands I've knocked up a cheap and cheerful database but using a popup form rather than an inputbox tp pick up the date. If Lac is interested I have posted it and he can examine it.

Brian
 

Attachments

Thanks, all.

I've got it working (with an unbound text field for the date) and it's been delivered to my boss who is very pleased with it (so far).

It probably isn't very elegant when it comes to the programming (I'm no where near as good as you guys -- yet)... and I've printed and saved this whole thread to try and figure out/implement the other options for my own edification. And, of course, saved the example database for up-close examination.

Thanks again.
 
A bit late but wouldnt something like
Private Sub date1_AfterUpdate()
Me.date1.DefaultValue = "#" & Me.date1 & "#"
End Sub
Where date1 is the name of the date field be simpler?

Peter
 
Guys. Do you realise Lac has very little experience in Access? You sound like Eskimo's talking in Eskimo about the higher mysticism of their religion would sound to you.
 

Users who are viewing this thread

Back
Top Bottom