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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

plez help! Can't create new record

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi everyone, I am used to database but I'm new to access. What I try to do is to have a form bound to a table and, when the primary key field is changed on the form, I want the show the corresponding info for that particular key value, or, if the key does not exists, I want create a new record (so the user can enter the info directly on the form.

So

if the key entered already exists : other fields refresh themselves

if the key does not exists : create record and other fields empty themselves so the user can enter data in them.

Please tell me if im not clear.

Thank you very much for the help!
 
It sounds like you need to use a combobox on your form for the primary key of your table (I take it your primary key is NOT an autonumber). The combobox's AfterUpdate event can populate the other fields/controls on your form when an existing key is entered. The combobox's NotInList event can handle the cases when there is no such key in your table, allowing you to add a new record with the new key.

Is this what you're after? lastout (the game's not over till it's over)
 
Thanx, but I can't get it to work. When I change the primary it simply the current record primary key field instead of creating a new record. If the primary I enter already exists for another record I get a key violation error of course... think I'm missing something there. All the fields on my form are linked to the corresponding table. Is that the right thing to do?
 
In the property sheet for your combobox, is LimitToList set to No? It should be set to yes if you are going to use NotInList to add a value to the combobox list (i.e. a new record). If LimitToList is set to No, the NotInList event won't fire. Oh, and something else...the ControlSource of your combobox should be blank. The combobox should be getting its records through the RowSource property from an SQL statement.

Let me know how it goes. lastout (the game's not over till it's over)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top