Regarding défault values in Sub forms

Trisha2014

New member
Local time
Today, 04:07
Joined
Mar 10, 2014
Messages
6
Dear,

I have a form with a sub form.

In the sub form I have a column named date.
When user need to add new data in the sub form the date field will autimatically show todays date .

I have added in the default value properties of the date field as Date ().

But with this I am facing a problem.

When I start entering new data in the data sheet of the sub form, the sub form automatically creating a new line with the default date value.

which in terms creating a new records in the database table.

Is it possible to restrict creating of a new row with the défault date value.

The below case is when new records are entered in the sub form a new row created with the date field
in this case the row is where colunm 1 data is 11AB.

But as soon as I type data in column 1 (rest of the column blank)a new row with date field already created.


Main Form

Date = 3.11.2014
Employee = ABCD

Sub Form


Column1......... Date ....... Column3
11 AB.......... 3.11.2014
................... 3.11.2014
 
Last edited:
Where is the default value being set: in the form or in the underlying table? Try doing it in the table instead of the form maybe and see if that helps.

If that doesn't work, then you could use code in the subform's BeforeInsert to set the value that way it will only be set when the user clicks to add a new record.

The code would be something like this:

Code:
Me.YourControlName=Date()
 
By the way, this should have been posting in the forms section not in queries...
 
Dear EternalMyrtle,

Thanks for your support it helps by setting the défaut values in the table level.

Also sorry to mention the post in the queries section by mistake.
 
Dear EternalMyrtle,

One small question,

Code:
Me.YourControlName=Date() is also valide for Access 2000

Because for me the code didn't work in Access 2000
 
I don't know. I am using 2007. If the date function is working in the rest of 2000 then it should work in VB too. Maybe try getting rid of the parenthesis after the date. So just

Code:
Me.ControlName=Date

If that doesn't work: make sure you are referencing the control name in your code and not the field name.

To see the control name open your form in design view, open the form properties go to the Other tab and click on the control. The control name is what is listed in Name
 

Users who are viewing this thread

Back
Top Bottom