check for a value displayed in a subform

I have a subform on a main form that displays query results.  It displays 4 fields of data, which is also the number of fields in the table that is being queried.

One of the comboboxes on the main form is tied to another table that lists abbreviations of all states in the United States.

When the user makes a selection from that combo box, a Docmd.Requery is invoked and the query results for the selected state are displayed in the subform (the query gets the value to look up from the selection made in the combobox)

So, for example, let's say the user opens up the main form and selects 'NY' from the combobox.    The query will return results that look something like this in the subform:

Field1        Field2        Field3         Field4
NY             whatever   whatever   whatever
NY             whatever   whatever   whatever
NY             whatever   whatever   whatever

Notice that only 'NY' records are returned.  Without going into too much detail about why I need to do this, what I'm trying to accomplish is, once query results are already displayed on the screen (use the NY records above as an example),  I want to be able to detect if a subsequent selection from the combobox is different from what's already displayed on the screen before allowing the query to run again.   Say, for example the 'NY' records are already displayed.  If the user then selects 'CA', I want to be able to detect that the combobox selection (which happens to be 'CA') is different than the data in Field1 of the query results currently displayed.

I know I wrote a book trying to explain this but all I'm trying to do in plain English is:

If combobox selection <> data in Field1 of subform (it doesn't matter which row is looked at because the values in Field1 of the query results will all contain the same value)  then
msgbox "You selected a different state than the one currently being worked on. Would you like to switch states or cancel your selection?"  blah blah blah

Thank you
Who is Participating?
IrogSintaConnect With a Mentor Commented:
You would you do something like this:
If Me.NameOfComboBox <> Me.NameOfSubformControl.Form!Field1 Then

Open in new window

dbfromnewjerseyAuthor Commented:
thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.