Why access add blank record in table

J

Jon

Greeting,
I have a table without Primary key. When I want to add new records in this
table, I open form to do that. The problem is when I decided to exit this
form without adding new records; a blank record has been added to the table.
Note: there is a macro in on load of the form event to reset the value of all
textboxes and combos.
Any help please
 
T

Tom Wickerath

Hi Jon,
I have a table without Primary key.

That's your first mistake. Every table *should* have a primary key (or, as a
minimum, a uniquely indexed field).
The problem is when I decided to exit this
form without adding new records; a blank record has been added to the table.

Are you opening the form in add new mode? With the record selector
displayed, is the form dirty (ie. do you see a pencil symbol in the record
selector)? If so, try issuing a Me.Undo when closing the form, if your macro
is dirtying the form.


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
J

Jon

Thank you Tom,
I did what you said, and it works

Tom Wickerath said:
Hi Jon,


That's your first mistake. Every table *should* have a primary key (or, as a
minimum, a uniquely indexed field).


Are you opening the form in add new mode? With the record selector
displayed, is the form dirty (ie. do you see a pencil symbol in the record
selector)? If so, try issuing a Me.Undo when closing the form, if your macro
is dirtying the form.


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
T

Tom Wickerath

Hi Jon,

Glad to read that you got it solved.

By the way, I'm curious about your earlier statement:
Note: there is a macro in on load of the form event to reset the value of all
textboxes and combos.

Why should these controls need resetting when the form loads? Frankly, I've
never heard of such a thing.


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
J

Jon

Hi,
The point of resetting textboxs is to be blank and the user can not modify
the first record in the table. You know when the user need to add new data ,
access display the first record. This may lead to modify the record. Hope you
get my idea!!
 
T

Tom Wickerath

Hi Jon,

Please explain more, if you don't mind....

I take it you are opening a bound form (ie. a form that has a recordsource
property specified, as opposed to an unbound form that has no recordsource).
Are the controls also bound (ie. include a control source property)?

What exactly is/are the action(s) carried out by the macro called out in
your form load event procedure? Are you navigating to a new record? If so,
why not just open the form in add new mode. For example, VBA code behind a
command button on a switchboard might look something like this:

DoCmd.Openform "FormName", DataMode:=acFormAdd

where FormName is the name of the form you are opening.


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________
 
J

Jon

Hi,
Suppose that you have a tbl called emp_tbl, and you want to add new emps to
the tbl. emp_tbl hase five fields: emp_ID(PK), emp_name, sex(male or female),
mobile_No., and email. in this case you need to create a form abound on
emp_tbl to input the data. First of all, create a form (New_emp) and make the
record source of the form be emp_tbl. second , put all field in this form by
drag and dorp. After that you will have 4 txt box and one combo box(for sex
field: male and female) , after that, you need to add a cmd button to add new
record and cmd button to exit from the form. In the form property, set the
format as follows:
Record selectors: No
Navigation buttons: No
Divide lines: No
And with Data tab set "Data Entry" : Yes.
Now I will create a macro and it has the following action:
-SetValue
Action argument:
Item: [Forms]![New_emp]![emp_ID]
Expression: ''
-SetValue
Action argument:
Item: [Forms]![New_emp]![emp_name]
Expression: ''
And so on for the rest of txtbox
-Gotocontrol
Control name: [emp_ID]
After that you need to go to the event tab of the form(New_emp) and go to on
load event and put the macro there.
Finally save your job and test it. You will see blank text and you need to
fill up the txtbox without seeing the previous data.
Hope that i express the idea of the setting value of form.
if you need more clarification, please feel free to ask me?
Thanks
 
T

Tom Wickerath

Hi Jon,
And with Data tab set "Data Entry" : Yes.

If you have this property set to Yes, then you should have never seen
existing data for the first record, as you indicated in your previous post.
The navigation buttons should indicated Record 1 of 1, until you add your
first record. Then you will be able to see new records just added, until you
close this form. The next time you open it, you should be back to Record 1 of
1. Try turning your Navigation buttons back on, temporarily, to see this.

It's no wonder your macro was dirtying the record. As best I can tell, it
should not necessary to call your macro. If you care to send me a stripped
down version of your database, with the table, fields, form and macro that
you described, I'll be happy to look at it. I simply don't think that you
need this macro, but I'll be able to tell more, by looking at an actual
sample. If you are interested, send me a private e-mail message with a valid
reply-to address. My e-mail address is available at the bottom of the
contributor's page indicated below. Please do not post your e-mail address
(or mine) to a newsgroup reply. Doing so will only attract the unwanted
attention of spammers.


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

Jon said:
Hi,
Suppose that you have a tbl called emp_tbl, and you want to add new emps to
the tbl. emp_tbl hase five fields: emp_ID(PK), emp_name, sex(male or female),
mobile_No., and email. in this case you need to create a form abound on
emp_tbl to input the data. First of all, create a form (New_emp) and make the
record source of the form be emp_tbl. second , put all field in this form by
drag and dorp. After that you will have 4 txt box and one combo box(for sex
field: male and female) , after that, you need to add a cmd button to add new
record and cmd button to exit from the form. In the form property, set the
format as follows:
Record selectors: No
Navigation buttons: No
Divide lines: No
And with Data tab set "Data Entry" : Yes.
Now I will create a macro and it has the following action:
-SetValue
Action argument:
Item: [Forms]![New_emp]![emp_ID]
Expression: ''
-SetValue
Action argument:
Item: [Forms]![New_emp]![emp_name]
Expression: ''
And so on for the rest of txtbox
-Gotocontrol
Control name: [emp_ID]
After that you need to go to the event tab of the form(New_emp) and go to on
load event and put the macro there.
Finally save your job and test it. You will see blank text and you need to
fill up the txtbox without seeing the previous data.
Hope that i express the idea of the setting value of form.
if you need more clarification, please feel free to ask me?
Thanks
 
J

Jon

check now Tom, I have sent you an email and my email address strats with "g"
thanks in advance

Tom Wickerath said:
Hi Jon,
And with Data tab set "Data Entry" : Yes.

If you have this property set to Yes, then you should have never seen
existing data for the first record, as you indicated in your previous post.
The navigation buttons should indicated Record 1 of 1, until you add your
first record. Then you will be able to see new records just added, until you
close this form. The next time you open it, you should be back to Record 1 of
1. Try turning your Navigation buttons back on, temporarily, to see this.

It's no wonder your macro was dirtying the record. As best I can tell, it
should not necessary to call your macro. If you care to send me a stripped
down version of your database, with the table, fields, form and macro that
you described, I'll be happy to look at it. I simply don't think that you
need this macro, but I'll be able to tell more, by looking at an actual
sample. If you are interested, send me a private e-mail message with a valid
reply-to address. My e-mail address is available at the bottom of the
contributor's page indicated below. Please do not post your e-mail address
(or mine) to a newsgroup reply. Doing so will only attract the unwanted
attention of spammers.


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

Jon said:
Hi,
Suppose that you have a tbl called emp_tbl, and you want to add new emps to
the tbl. emp_tbl hase five fields: emp_ID(PK), emp_name, sex(male or female),
mobile_No., and email. in this case you need to create a form abound on
emp_tbl to input the data. First of all, create a form (New_emp) and make the
record source of the form be emp_tbl. second , put all field in this form by
drag and dorp. After that you will have 4 txt box and one combo box(for sex
field: male and female) , after that, you need to add a cmd button to add new
record and cmd button to exit from the form. In the form property, set the
format as follows:
Record selectors: No
Navigation buttons: No
Divide lines: No
And with Data tab set "Data Entry" : Yes.
Now I will create a macro and it has the following action:
-SetValue
Action argument:
Item: [Forms]![New_emp]![emp_ID]
Expression: ''
-SetValue
Action argument:
Item: [Forms]![New_emp]![emp_name]
Expression: ''
And so on for the rest of txtbox
-Gotocontrol
Control name: [emp_ID]
After that you need to go to the event tab of the form(New_emp) and go to on
load event and put the macro there.
Finally save your job and test it. You will see blank text and you need to
fill up the txtbox without seeing the previous data.
Hope that i express the idea of the setting value of form.
if you need more clarification, please feel free to ask me?
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top