How to place inserted values from one field to another based on selected combo box values in a different form (1 Viewer)

Mainman

New member
Local time
Today, 17:01
Joined
Dec 14, 2021
Messages
9
I have created a combo box in a form. The user can select two options. If a specific option is selected, values earlier inserted in a specific field of a different form should be automatically removed there and inserted in the column which is selected in the other form. Does anybody know how to achieve this in MS Access? I am a total beginner at VBA code. Would it be an idea to create an event procedure on change where I update the fields in the first form based on the selection of the combo box?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:01
Joined
Oct 29, 2018
Messages
21,360
Hi. Welcome to AWF!

If the other form is still open, you can manipulate it from the current form. Otherwise, you could use an UPDATE query to change the data in the underlying table.
 

Mainman

New member
Local time
Today, 17:01
Joined
Dec 14, 2021
Messages
9
Hi, Thanks! The first form would still be open when the box value would be inserted so any update would just show immediatly within access(the underlying database is in SQL. The access forms allow for data entry in SQL). Would adding code in the change part within the event procedure of the combo box be a good start?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 12:01
Joined
Feb 19, 2002
Messages
42,990
Forms don't hold data. Tables hold data. Therefore, this is wrong thinking. You don't think about updating a form, you think about updating a table. You need to update the underlying data. Also, in general, you shouldn't normally have multiple forms open/visible. But if you do, and it is the calling form's data that you will be updating do it this way:
1. Before opening the pop up form, save the current record to ensure that it isn't dirty.
2. open the second form as modal so that code execution in the calling form stops.
3. Do whatever needs to be done in the pop up form. If you are changing something that affects data visible on the calling form, use an update query.
4. When the pop up form is closed, control will return to the calling program at the line after the DoCmd.OpenForm. That line should be - Me.Requery and that will pick up the changes made by the pop up form.
 

Micron

AWF VIP
Local time
Today, 12:01
Joined
Oct 20, 2018
Messages
3,476
cross posted

@Mainman, maybe read
 

Mainman

New member
Local time
Today, 17:01
Joined
Dec 14, 2021
Messages
9
Ok thx for pointing that out. I'll continue here then. I'll attempt to issue a change event which will update it in the SQL query and see if that'll work.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 00:01
Joined
May 7, 2009
Messages
19,175
can you not have the combo on Same form (form1)?

it would be easier to code on same form rather than on two forms.
if you are in Edit mode on the first form, you need to either save the changes first
or cancel the changes and go on and apply the changes from the combobox.
 

Users who are viewing this thread

Top Bottom