Enforce Data Validation Between Subforms

Eastman

New Member
Joined
Mar 18, 2011
Messages
2
Hello,

I am trying to make a form with multiple subforms be able to detect if the value in one textbox in one subform is equal to the value of another textbox in another subform. If they are not equal, then an error message is displayed when the button is clicked.

Would it be like

Code:
If [Forms]![MainForm]![Subform1].[Form]![Textbox1] <> [Forms]![MainForm]![Subform2].[Form]![Textbox2] Then
Msgbox "Values do not equal"

When I ran the code, the msgbox always popped up even when the values in both text boxes were equal. What am I doing wrong?
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Ziggy

Active Member
Joined
Feb 15, 2002
Messages
337
are you re-querying the controls after data is updated in them?

Try to debug what the controls are seeing by using a message box, stepping through the code line by line and check each reference to the controls in the Immediate or Watch windows..


in case you don't know.... open the code window and set a break point by clicking on the screen to the right of the code window at the line where you first encounter the reference to the controls.... then run code from form ( or press F5 in code window with cursor in sub)... code should break with yellow line... now Press F8 until the yellow line passes over the control references....

Next click in immediate window and type...

?[Forms]![MainForm]![Subform1].[Form]![Textbox1]

then again with...

?[Forms]![MainForm]![Subform2].[Form]![Textbox2]


this should display the results of those controls, then you will see where the problem is.


watch out for spaces because perhaps one control has data with spaces, so you may want to surround the expressions with a TRIM function.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,271
Messages
5,600,650
Members
414,399
Latest member
Ninjee

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