Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form keeps adding new recoed to table

Status
Not open for further replies.

darkmage1

Technical User
Jan 30, 2005
28
US
On my main form I have a combo box that I can select the movie I want then click on the control button to open another form to display information about the title of the dvd movie I have selected. Everytime I do this I notice that there is a new record added to the main table. Is there a way to do without adding new records or information to the tables?
 
It's only adding new records if somehow you are telling it to. Look through all your controls' code (combo box, command button) and the pop-up form's events and properties to see what you've put in there.

Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
ChaoticEmpire

There are two possible things happening...
- You are not creating new records, but an AutoNumber field is advancing
- You are creating a new record.

As stated by GingerR, your command button is doing something that is causing the quirky beahviour.

First, to verify you are creating new records, or not, a safe way to test for this is to use the Query Builder to create a simle query to display your records. If the records keeps increasing, when you re-run the query after pressing the command button, yep, you are creating additional records.

Next, what type of records are you creating -- duplicates, empty records?? Two things here -- a well designed application will accommodate two things:

a) Avoid the creation of bad records such as empty records. You can control this behaviour somewhat by changing the table design to ensure certain fields have required data.
For example, for a DVD collection, you want a title. Open the main table in design mode, and select the field used to capture the DVD titles. Make it a reqired field by tweaking the field properties.

b) Avoid the creation of duplicate records. If you have Video rental store, you may have five copies of Million Dollar Baby but each copy should have it's own reference. Your primary key is suppose to achieve this "uniqueness", but you can further prevent the occurence of duplicates by using the Title + CopyNumber (to document number of copies), and create a unique index for this pair...
[tt]
Title Copy

Million Dollar Baby 1
Million Dollar Baby 2
Million Dollar Baby 3
[/tt]

Assuming you have a "copy" field on the taable, to achieve this, open the table in design mode. From the menu, "View" -> "Indexes". Fill out the index definition as follows...
[tt]
Index Name Field Name Sort Order

OneCopy Title Ascending
Copy
[/tt]

For the Index named OneCopy, using the index properties, set the Unique field to "yes". (And yes, you would have to add the field "Copy" to your form.)

Now, you have to change the copy number each time you add the same title.

The aforementioned should give you some ideas how to prevent bad data without having to make numerous coding cheecks with the data entry screen.

But what is the command button doing?? Well, one thing that comes to mind is that the form is defined for "DataEntry" (= yes) which would mean every time you opened the form, it would assume data was to be entered.

With the form open in design mode, use the Properties window to change the DataEntry to "no"

I realize you must be frustrated, but you are making great progress. Well done...

Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top