How to prevent aForm from showing default value from table field in blank new record? (1 Viewer)

shwan

Registered User.
Local time
Today, 09:28
Joined
Nov 18, 2017
Messages
13
Hello,

I'm new to access and I have this little problem that is bothering me.
I have a subform based on a table that has a field with the default value set to current date using the date function.
Every time I open this subform an empty new record shows below whatever records is already there which is fine, the problem is that: this new blank record has nothing except the date, which is the default value from the table.
How can I prevent this date from showing until the user starts to actually enter a new record??

Thank you very much
 

isladogs

MVP / VIP
Local time
Today, 17:28
Joined
Jan 14, 2017
Messages
18,258
Remove the default for the field.
Add it using code when a new record is entered.

Access also unhelpfully used to set the default for number fields to 0.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:28
Joined
May 7, 2009
Messages
19,246
remove the Default Value from the table.
 

shwan

Registered User.
Local time
Today, 09:28
Joined
Nov 18, 2017
Messages
13
Thank you for your replies, If I remove the default value from the table, how could I add the date automatically when a new record is entered? I want the user to see that the date has been added. Can you please share the code for that.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:28
Joined
May 7, 2009
Messages
19,246
use BeforeInsert code of the form;

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.yourDateField = Date()
End Sub
 

shwan

Registered User.
Local time
Today, 09:28
Joined
Nov 18, 2017
Messages
13
use BeforeInsert code of the form;

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.yourDateField = Date()
End Sub

Thank you very much, sir. That was helpful.
 

missinglinq

AWF VIP
Local time
Today, 12:28
Joined
Jun 20, 2003
Messages
6,420
Set it as the Default Value for the Control, at the Form level...then, when a New Record is started, it'll automatically appear!

Linq ;0)>
 

Users who are viewing this thread

Top Bottom