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!

On Exit

Status
Not open for further replies.

VTbigwillie

Programmer
Jul 23, 2002
9
US
I have a data entry form where its controls are tied to a table. The only time I want a record to be added to the table is when the Add record button is pushed.

When I close out my form, if the correct information is in the form, the record will be added. Is there a way to prevent this?

Thanks in advance,
Will
 
I think you have your form set as a Data Entry form. This would automatically place any data into the table upon exiting.

Also, when you close your form (or code for the form to close) On Close or Unload, you need to make sure that it doesn't save.

DoCmd.Close acForm, "ThisForm", acSaveNo

There's some added thoughts and ideas for you. See how these work and let me know if they did/did not work. :) Roy McCafferty
aka BanditWk

Las Vegas, NV
roy@cccamerica.org
RLMBandit@aol.com (private)

"I do this because I know I can - no need to send gifts - just send me a smile to show me that I've helped." ~ seen on a cardboard sign held by Roy McCafferty on a corner in Las Vegas
 
Unfortunately, neither of your suggestions worked. When I unload the form, close it, or press the quit button (which is where I placed the acSaveNo code in) they all sent the data to the table anyway. And yes, the data entry option was turned on and that also had no effect when I turned it off.
 
Have you thought of saving all the data to temporary variables and applying the add only when the add record button is pushed? I'm not sure if that's worth while. Just a thought.

Ed
 
Yes, in fact that is what I would prefer to do BUT in order to do this, Access tells me I have to set the focus on each of my controls before I grab their values which seems odd to me. Is there a better way to do get the contents of my textboxes?

Thanks,
Will
 
You should be able to get the contents of the textboxes without having to setfocus. I created a dataentry form and wrote a bit of code to process it into the tables just fine. This is how I tested it and it works. It might not be what you are looking for if you created your form using the form wizard. Since you created it using the form, Access might just be putting data in as soon as data gets inputed into the text boxes.

With CurrentDb.OpenRecordset("yourtable")
If Not (IsNull(Forms![People].txtID)) Then
.AddNew
![User ID] = Forms![People].txtID
![First Name] = Forms![People].txtFname
![Last Name] = Forms![People].txtlName
![Age] = Forms![People].txtAge
.Update
End If
End With

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top