Changing Values of Text Box on Main Form from Sub Form

CPGDeveloper

Board Regular
Joined
Oct 8, 2008
Messages
129
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

xenou

MrExcel MVP, Moderator
Joined
Mar 2, 2007
Messages
16,628
Office Version
2013
Platform
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,095,841
Messages
5,446,822
Members
405,417
Latest member
egrospe17

This Week's Hot Topics

Top