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

Check whether or not a record exists before adding a new one?

Status
Not open for further replies.

Accesser

Technical User
Jun 3, 2002
44
0
0
US
Hi there,
I'm having a prob figuring out the best way to do this:

I have a form that's set to add a new record when a user opens it. On the form is a combobox (comboName) that the user can type in. If the user enters a name that's new or not already in the combobox list, everything's fine & dandy. However, if a user starts typing a name that's already entered, then I need the form and it's auto ID (NameID) to revert back to the record that's already entered. And consequently, I don't need to keep the 'new' record just added upon opening the form. Is there some code that will do the following:

check the names list for the newly entered name, and if the name is new, then add a new record and keep the name that was just entered, if it's not, then go back to the record that's already entered and display it's data.

Thanks much,
Eric
 
I'm not sure how you'd do that with the combo box.

What I usually do is to start with a small input form, an unbound form with one field into which the user enters the data you want to test for (in your case, the name). A command button on the form tests for the presence of a record with a field matching what was input, and then opens the main form accordingly.

With the name entered in the initial form, you can then test for the presence of that record and either open the form to that record, or open a blank form for data entry.

To do this, I do a DCount to count the number of rows which contain a field whose value matches what the user input and assign that value to a variable. If that variable's value is greater than 0 (i.e. you have at least one row matching the name you entered), you can then open the appropriate record. If that variable's value = 0, you know that no rows exist and can open up a blank form. - - - -

Bryan
 
Make the form that u add records in a subform, in a form having an ID linked to the ID U want to check in the subform. Once you type the ID in the ID in the Form, if the record is present it will automatically appear in the subform, if not it will be empty, so u can write in it your data.

Maged [pipe]
 
Hi,
This is the problem that I am having put my users are putting info in based around dates. If the date exsits I would like all the values allready enetered for that date to be loadedl if the date doesnt exsist, I want the date to be created. Sorry to be a pain, but Im not really familiar with sub forms and ID Numbers. Please can you help

regards

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top