|
-
Jun 8th, 2006, 10:52 AM
#1
Thread Starter
Hyperactive Member
VBA Adding a record to table
I am using access to create a form for the user to input data through and store it in a table. I am having a little trouble with "adding" the inputted data from the form to the table.
1) If I use the scroll bar on the mouse it will move forward to a new blank record and any data on the previous record is automatically placed into the table.
2) After hitting tab on the last text box it automatically inputs all the data into the table and create a new blank record.
I do not want to allow the user to use these options to add the record to the table. What I want to do is place a simple command where the user "must" click on in order to save the data to the table. Otherwise, the information is not saved. What do I need to do to prevent the user from using the above two methods to save data?
Last edited by lilmark; Jun 8th, 2006 at 11:34 AM.
-
Jun 8th, 2006, 03:36 PM
#2
Addicted Member
Re: VBA Adding a record to table
This may be a little inefficient, but you could open the form as read-only, and when the user clicks "Save", store all of the values of each control into an array (or temporary record), close the form, acSaveNo, then either enter the values directly into the table or reopen the form as changeable and enter in the values.
If you are looking for the typical UI "Save" and "Cancel" buttons for the user's peace of mind, you could do this:
1.) Using the forms before_open or initialize event (can't remember which one - use the very first event triggered when the a form opens), copy the record in the table to a temporary record.
2.) If the "Save" button is clicked, simply close the form and delete the temporary record, since everything is automatically saved.
3.) If the "Cancel" button is clicked, close the form and copy the contents of the temporary record back into the current record, then delete the temporary record.
Hope this gives you some ideas to work off of...
-
Jun 8th, 2006, 04:53 PM
#3
Thread Starter
Hyperactive Member
Re: VBA Adding a record to table
I think I tried the read-only idea already. I set the form's Allow Additions property to No. And, I also tried Form_Load and using the code DoCmd.OpenForm ,,,,acReadOnly
But, if the user hits tab after the last object is target or if the user uses the scroll button on their mouse it'll save the data still. hehe
-
Jun 9th, 2006, 10:29 AM
#4
Addicted Member
Re: VBA Adding a record to table
Did you try my other suggestion?
-
Jun 9th, 2006, 01:55 PM
#5
Thread Starter
Hyperactive Member
Re: VBA Adding a record to table
The save button is easy. I did that already. What I want to know is there a way to get around so the user cannot accidentally save by move the scroll button on their mouse or hitting the tab key after the last object is targeted?
Last edited by lilmark; Jun 9th, 2006 at 02:40 PM.
-
Jun 9th, 2006, 03:38 PM
#6
Addicted Member
Re: VBA Adding a record to table
There may be an event that is fired when any key is pressed (or mouse scrolled) that triggers the control values to be saved. If this is the case (and someone else can provide that event name), then set the cancel parameter of that event to true to cancel the event.
VB Code:
Private Sub Form_EventName (Cancel As Boolean)
Cancel = True
End Sub
However, if there is no event that handles any shift of controls, then an easier solution may be what i have already suggested, that way it doesn't matter if the information is saved or not.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|