Compare two controls and use result to trigger msgbox

  • Thread starter Thread starter James W
  • Start date Start date
J

James W

Hi there.

I have built a search facility on a form where the user enters the
SearchString into an unbound text box.
A macro then moves the focus to the control containing the data to be
searched.
The macro then runs a FindRecord and, if found, the details are displayed on
the form.

What I want is to trigger a msgbox saying eg. "Search String not found" if
there is no match in the Recordset.

I assume the way to do this is to compare the Control containing the data to
be searched with the value in the unbound Text Box and then based on that
result display the msgbox.

E.g: [Control containing search data] <> [SearchString] Display Msgbox

Thus far I have not been able to get this to work.

Any help would be greatly appreciated.

T.I.A.
 
See the Condition column in the macro (you may need to make it visible from
the toolbar / menu). Put your expression in that column.
 
Thanks for the response Ken.

The problem is not where to enter the condition it is what is the condition
itself?

ie [Control to Search] <> [SearchString] Does not work.
 
Alternatively, perhaps you could use the DCount function to test the form's
RecordSource for whether the record exists:

DCount("*", Forms!FormName.RecordSource, "FieldName='" &
Forms!FormName!SearchString & "'")=0

--

Ken Snell
<MS ACCESS MVP>

Ken Snell said:
Forms!FormName!SearchControlName <> Forms!FormName!SearchStringControl

--

Ken Snell
<MS ACCESS MVP>


James W said:
Thanks for the response Ken.

The problem is not where to enter the condition it is what is the
condition
itself?

ie [Control to Search] <> [SearchString] Does not work.
 
Back
Top