How to edit a record through a form on MS Access? - sql

I'm new to Microsoft Access and I'm having a trouble implementing something.
Basically, I have a form with a combo box, some text boxes, and a command button.
What I want to do is have the user select a record from the combo box, which then populates the textboxes (I've already managed to do this). Once the data has loaded into the textboxes, I want the user to be able to edit the info in the textboxes, then press the command button so that it updates that record in the table.

This looks like the same odd form where you had trouble with delete. It sounds like you are working from the wrong end. Create a form based on a table or query, then add a combobox to find records on the form based on the selection. There are wizards to guide you through. You will then have a standard Access form where everything works as expected. When textboxes are changed, the data will be updated as soon as you move to another record, there is no need for save, it is the default for Access.
If you wish to use non-standard unbound controls, you will need to update with SQL or stored queries.

Related

in Access, Bound Combo Boxes do not update unless the form is already Dirty

I'm working on a fairly complex Access Database, trying to build forms with custom buttons for working with records. I'm using list boxes to display and navigate through records and all fields for existing records are disabled unless the user presses an edit button. The problem I'm having is that if I press the Edit or Add New button, enabling all of the fields, and then try to change the selection in a combo box, it does not update on the first try.
If I edit a text box first then the combo boxes work fine.
I've determined that the control's beforeUpdate and afterUpdate events are not firing on the first try but the action triggers the form_Dirty event and then it works as expected. I tried setting Me.Dirty = True with the Edit button and that solved the problem but it causes problems with some of my other code and it seems like an unnecessary workaround if only I understood the actual cause of the problem. It also works as expected if I leave the Combo Box unbound, but I am trying to build a template that doesn't require too much work to build new forms off of and I would rather not go that route.
It must have something to do with some bit of code I'm using because I can start a basic form and the combo boxes work fine.
I've started a basic test form and am adding code from my template form bit by bit until the problem arises, but it's a tedious process. Any help would be appreciated.
What am I missing? Is there some way of getting the Combo Box events to fire before the form is dirty?
UPDATE:
I have templates for a basic form, a form with a single subform, and a form with multiple subs in a tab control.
After some more testing I discovered that this problem does not apply to the basic form which has no subforms. This template uses similar code to the others for new, edit, cancel, save and delete buttons and for preventing accidental changes, preventing Form_unload during an edit and so on. The main difference I can think of off the top of my head is that the templates with subforms use class modules and collections to hold various data and pass it between the main form and subforms. Not sure if or how this might relate to combo box functionality.
I built most of this last winter then got too busy over the summer to work on it. Just now picking it up again and I'm having to re-learn a lot of the details of how my code works.
you can try to use Me.CboName.Requery in your After Update event.
I figured it out. I was calling a procedure with a form refresh in it from the Form_Dirty event and for whatever reason the refresh at exactly the wrong time was causing the combo box Before_Update and After_Update events to be skipped and the combo box value to not change. It was also causing text entered into a textbox to overwrite existing text on the first keystroke.

Which form event to use to update a form once form has loaded

A text box on my MS Access form needs to display a value once someone enters information onto the other fields in the form. The text box has a control source from a table so once someone enters information into the other fields, the set box should display the from the table it is linked to. So essentially, I entering the information into the other fields locates the record and field that my textbook should display.
Should I add an event procedure to the Form_Load event? or do I add an event procedure to the txtbpx_AfterUpdate event in order to display the value of the textbook?
I am new to using MS access forms so please answer while keeping in mind that I am a new user of MS Access form.

Ms Access 2007 ComboBox

I am using Access for a quick and dirty (ADP) interface for an SQL (Express 2012) database so data entry can begin before the MVC web app interface is complete.
There is one field I want to be varchar, I would like this field to either allow the user to type in a value or select from a distinct list of values previously used in that field.
I have that part down, but the problem is when it happens, I have to refresh the recordset to see the new item in the list, so if they choose add a new record, then the last item added is not visible in the list.
So I can get the distinct list, populate the box, allow for new entry, and save that to the DB, do I have to write a code behind to repopulate the recordset, do I need to write a code behind to maintain the list paralleled to the recordset, or is there just a property I am missing?
Thanks
(Added screen showing event)
As suggested, using the on current event on the form and the after update solved the problem.
Clicking the form section detail selected the detail sections property page not the form. Selecting the form from the drop down on the property page displayed the events I was suggested to use.
Many thanks to those contributing.
As the first suggestion of this was from Remau, with assist in locating that event from hansup, I will mark remau's post as answer. Thank you to both.
Don't requery the form, just requery the combo. The best bet is probably the current event which will work if more than one person is doing data entry. It will also work if people are editing the table as well as entering data. Events that only fire when a record is added will not pick up changes to the combo contents.
Private Sub Form_Current()
Me.MyCombo.Requery
End Sub

Delete button that actually deletes record from tables in Access

Im very new to Access, so theres a lot i dont know.
I've currently got a form that has a combo box, some text boxes, and a delete button on it.
I've managed to get the textboxes to autofill based on what the user selects from the combo box, but im stuck with how to go about deleting that record.
At current, my delete button was set up through Button wizard, and when pressed, only deletes the record from the textboxes on the form (clearing the form). What i want it to do is actually delete that entire record from the table that the form is based upon. I just have no idea of what the code i should put behind the button is.
Sorry if that makes no sense. Basically, all i want is a button that when pressed, deletes the record that the user has selected from the combo box, from the table that the record came from.
Thank you for any help!
The button wizard will give you a working delete button, however this deletes the current record, so you should ensure that your combo box changes the current record.
Note that if you are coding your own delete button you should use DoCmd.RunCommand acCmdDeleteRecord instead of the DoCmd.DoMenuItem calls that the wizard generates.

How to create Access textbox that I can just type into?

I need to create a textbox that a user can enter an arbitrary string into. No matter what I try, I always have to link the textbox with a query, table, or something else -- I just want to be able to type anything into a textbox. Is this possible?
Clarification: I'm using access 2003. Also, I'm talking about the user typing into it, not 'me'. Sorry about the confusion.
If your form is data-bound, then the data source must be updatable. Otherwise it will lock the form, including controls that are not data-bound. For instance queries with GROUP BY statements or UNION queries are not updatable.
If the form is locked or disabled in some way, all controls on that form will be locked or disabled as well.
EDIT:
AllowEdits is a form property, not a control property.
You don't mention which version of Access that you are using but every version that i have used up to Access 2007 has a unbound texbox. Try going into design mode on your form. In your title bar you should see something like this that will allow you to enter a textox on your form.
Once you drag that onto your form you should be able to type anything you want into it. Is that what you were asking or did I misunderstand your question?
When you create a text box it will say unbound. Leave it saying unbound.