Changing Values of Text Box on Main Form from Sub Form

CPGDeveloper

Board Regular
Joined
Oct 8, 2008
Messages
152
I want to change the value of a combo box on a main form based on the update of a combo box on a subform. I have the following:

Private Sub cmbSubCombo_AfterUpdate()
If Me.SubCombo.Value = 1 Then


Me.Parent!cmbMainCombo.Value = 1
Me.Parent!cmbMainCombo.Locked = True
If Me.Parent.Dirty Then
Me.Parent.Dirty = False
Me.Parent.Refresh


End If
End Sub


I keep getting the 'Write Conflict' Warning. I thought the Me.Dirty sequence would take care of that -- perhaps I'm missing something?
 
Last edited:

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,796
Office Version
  1. 2019
Platform
  1. Windows
I think a lot depends on the details? Is the subform related to the main form (i.e., parent-child or anything of that nature?). How are they related? Also, are the fields bound? If so what are they bound to? For example, can you just change the parent combo box field manually without any problems? How does this affect the data in both of the forms if you do that?
 

stumac

Active Member
Joined
Jul 16, 2010
Messages
471
the write conflict is probably because you are saving the record after updating it with code instead of before.

try saving it first:

Code:
[COLOR=#333333]Private Sub cmbSubCombo_AfterUpdate()[/COLOR]
[COLOR=#333333]If Me.SubCombo.Value = 1 Then
[/COLOR][COLOR=#333333]Me.Parent.Dirty = False
[/COLOR][COLOR=#333333]Me.Parent!cmbMainCombo.Value = 1[/COLOR]
[COLOR=#333333]Me.Parent!cmbMainCombo.Locked = True[/COLOR][COLOR=#333333]
[/COLOR][COLOR=#333333]End If[/COLOR]
[COLOR=#333333]End Sub[/COLOR]
 

Watch MrExcel Video

Forum statistics

Threads
1,123,189
Messages
5,600,219
Members
414,373
Latest member
jp1392

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top