Compare two controls and use result to trigger msgbox

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.
 
K

Ken Snell [MVP]

See the Condition column in the macro (you may need to make it visible from
the toolbar / menu). Put your expression in that column.
 
J

James W

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.
 
K

Ken Snell [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top