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!

Problem in Data Entry Form

Status
Not open for further replies.

SatishPutcha

Programmer
Mar 12, 2002
256
IN
Hi Everybody

I have created a data entry form in MS Access 2000.

This form has drop down lists which are populated with data from other tables in the MDB. The table into which the data of the form needs to go has been set as the "Record Source" in the form.

There are two buttons. One that is supposed to Add Records ("Add Records") and another that closes the form ("Close").

Now the problem is that no matter what action I do i.e. click Add or Close or even Close the form using the window's X icon, a record gets added into the table if values have been entered into the form fields.

Could anybody please tell me why this is happening?

Hope I have not missed out any detail. However please feel free to ask for further information about the database, form, tables, etc.

Thanks in advance

struggling_freelancer
 
Struggling,

Yeah, that's pretty much the way access works. In a bound form, such as the one you describe, there's no need to hit a save button, as Access will do the saving for you, as soon as you leave the record (which happens when you close the form).

If you want to have the record not be saved, I would suggest that you put some code in the save button that sets the tag property of the save button to "Save". Then put some code in the Unload or close event of the form that checks for this value and if it's not there performs an Undo on the form, which should toss the record without saving it.

A couple of notes: if you want the only way to close and save your forms to be with your buttons, you'll want to do a little more work. You'll want to hide the control box, close button, and record selectors of your form.

Hope this helps.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.


Remember to reward helpful tips with the stars they deserve.
 
Hi Jeremy

Thanks for your help. Nice to know that atleast what all I did was quite OK.

Could you please explain a bit more about the "tag" property for the Save button? How do I do it? Do I create a macro?

Also is there a way to do this if the form was not bound and instead I executed an "insert" query when the Save button was clicked? Please explain.

Yes,I did hide the record selectors. But why the control box and the close button(the X icon on the window, I assume)? Please explain.

Thank you again for the advice.

REGARDS
 
Struggling,

If you are going to do much serious developing with Access you'll want to drop macros pretty much entirely and start writing VBA code. It will take a _little_ bit longer to get into the swing of things, but once you do you will have a hugely more powerful tool in your hands.

That said, it would be possible to do it with a macro, however I couldn't tellyou how, as I've stayed away from them, on the basis of advice I got when getting into the business.

To set the tag in code, you would do this:
me!btnSave.tag = "Save"
(assuming your save button is called btnSave).

If you open your form in design mode and bring up the properties for the button and then bring up the code window in the Click event, you'll be able to do that right there. You'll also have to put in code to save the record. In a bound form that's as easy as me.dirty = false.

You could indeed do this using unbound forms, though I would say that if you're just getting into this, you should probably stick to bound forms for the time being.

Yeah, I guess there's no need to get rid of the close button and control box, it's just a habit I have, as I like forcing users to use my buttons to close the form, as it gives me more control.

Jeremy =============
Jeremy Wallace
Designing, Developing, and Deploying Access Databases Since 1995

Take a look at the Developer's section of the site for some helpful fundamentals.


Remember to reward helpful tips with the stars they deserve.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top