I'm working with Access 2007.
In my forms, if a user reaches the last record and accidentally clicks on the right arrow in the navigation bar, Access creates and automatically saves a new blank record. This results in the underlying table getting filled with blank records.
How do I stop this happening, in VBA or otherwise?
I have an Add button on the form to create a new record.
Browsing to a new record doesn't - on its own - create and save a new record.
So, remove the code you have, that either sets values of one or more fields or saves the record.
Related
I see that they work for the same purpose, both of them fill a record in a table, I can tell that the difference is that Add New Record put in blank all fields while Save Record does not. Am I right? Is that the hole difference?
An An Add New Record button moves the record pointer to the new record (at the end of the form or datasheet). If the current record was changed but not saved ("dirty"), Access must save the changes (or at least try to) on order to move the record pointer.
A Save Record button does not move the record pointer but save (or try to) the changes of the current record.
If in your scenario a "new record" gets saved with blank fields by clicking either button, there must be some background procedure that automatically fills a (maybe hidden) field in your form as soon as the record pointer arrives at the new record (thus making the record "dirty"). But this is not the default behaviour.
I have frmMain that has a number of subforms that are contained in several tabs on tab control on frmMain. I have subForm3 on one of the tabs of frmMain. subForm3 has a textbox control called tbxNote. tbxNote requires one user to make changes to the note based on feedback from a supervisor that is shown in a separate, non-modal popup form called frmFloater that appears above frmMain so that the supervisor's note shown in the non-modal form can be seen while tbxNote in frmMain.subForm3 is being editted.
Now, both frmMain and frmFloater can change the data in the same table. I understand that this is what is causing the write conflict error I am receiving.
So, I want to be able to trigger a save of the data in subForm3 when the user exits tbxNote, for example, the user exits by clicking frmFloater or a control in frmFloater. And, I want to trigger a save of the data in frmFloater when I exit frmFloater or click a control in frmMain.
The problem I am running into is that I cannot find an event that triggers when I leave frmMain or when I enter frmFloater; nor can I find an event when I leave frmFloater or when I enter frmMain.
I have tried the following events for frmMain (and also in frmFloater), none of which trigger when the user leaves frmMain (e.g., by clicking into frmFloater) nor do they trigger when the user leaves frmFloater (e.g., by clicking into frmMain):
On Deactivate
On Activate
On Current
On Click
On Got Focus
On Lost Focus
How can I detect switching to a different form so that I can save out the data in the first form before handing control over to the 2nd form?
If there are 2 forms showing 1 record, you will always run into problems. I would look at separating the record into 2 tables and creating a relationship between the tables to prevent corruptions of records. For example:
Table 1 will hold the main information of the record being viewed
Table 2 will hold the supervisor notes
The relationship between the tables will be either a 1 to 1 (if you want a note to be a single record and all updates the current note) or a 1 to many (if you want multiple records with multiple notes
be sure to check "enforce referential integrity", "Cascade Updating", and "Cascade Deleting". Otherwise you will have orphan records.
To answer your question, it cannot be done with the current setup. If employee A is editing the record on frmMain and a supervisor opens frmFloater and begins adding notes. You just corrupted the record... Reason being is, you cannot have the front end the employee has save the record the front end the supervisor has. only their machine can save the record the specific person has accessed. make sense?
There is another solution, and that would be making frmFloater an unbound form. There is quite a bit of programming involved to accomplish this, but once I made all my forms in my Access Databases unbound and all the controls unbound, I never had a corrupted record incident again. But this requires a button building the query before opening the form, open the form, then take the values from the query and place the values in the corresponding textbox on your form, then close the query. This will give you a snapshot view of the record on the table without being bound to it. Your button/afterupdate event can then run an update query on the record without locking it.
Let me know if this helped or if this did not make sense. If it didn't make sense, I'll try to explain a little better.
I have a data entry form that uses combo boxes with dropdown menus that was working as planned. I created a form to display the data using a QBE created query in datasheet view. When I come back to the data entry form, everything works except it doesn't write the data to the file.
I checked the record source for the form and the control source for the comboboxes and all is as it should be. I have a date in the file that is =Date() for today's date, and it appears in a new record but the fields are blank.
Any suggestion would be helpful.
Additional info, I did a compact and repair on the database but that didn't solve the problem. Sunday I copied everything to a new database and that didn't help. Copied to new database again, but only the data entry form, DE queries etc. Still no luck.#$#%$#.
New information added 6/13/16.
After further testing, the problem lies when I tab out of the last ComboBox. So the question is, what determines a write to the file: is it tabbing out of the last control? Or what?
Under Form Properties | Other
Set Cycle to "Current Record"
I've created a database revolving around a game, and I have a form for creating a character. There's a button on the form to create a character, provided data was entered in the characterName text box. However, I'm having an issue with adding the record to the Character table. It always replaces the first record or opens up a new blank table named Character with the same fields. I'm using the macro builder.
You shouldn't need a macro to add a new record to the table. Try this instead:
In the Navigation Pane on the left of your screen, click the Character table. Then go to the ribbon on top and under Create, click Form. This will make a form attached to your table. You can enter data into each field and it will all update to the table. Once you have made a few entries, you can use the navigation bar at the bottom of the form to browse between records, or create a new record.
I have form that loads as Data Entry = Yes and the navigation buttons are disabled. I'm trying to figure out how to make it to where a user cannot press SHIFT+TAB and go back through previously entered records. You have to press tab at the very last field to move to a new record just like you would the table.
Should I just close and reopen the form after update? Or is there a different way?
Thanks in advance
Before I answer the question, are you sure preventing the user from going backwards is a good idea? Perhaps they tabbed forward to make a new record and then realized they made a mistake so they want to go back and correct it? Of course, this depends on the specific needs of your db and how it will be used.
The Cycle property in the Other tab defines how tabbing works. If you change this to Current Record, then the user cannot tab backwards or forwards to other records.
If the user needs to add multiple records at once, you can add a command button.
Edit
Regarding your idea on the submit button, here's how you can make that work. Leave the form's record source blank (so it isn't tied to the table). When the users click Submit, a msgbox will first pop up asking them to save and warning them they can't go back. If they choose Yes, a SQL query stored in the VBA will then append the form's values to the target table, then clear the form.
The only potential problem with this is if the user enters single or double quotes to any string fields as those can mess up your SQL query. A simple Replace() can fix that though.