Re: Macro for Error Message



Thank you for the help on the null vs. blank.

As to my main question - If the user enters "James" as a [First Name] and
there are no entries in the data database for "James", I need an error
message. If there is a record for "James", the macro needs to move to [Last
Name]. If the user enters "James" for [First Name] and "Smith" for [Last
Name] and there are no records to match both fields, the user should get an
error message. (The user will enter both first and last names).

The third field is [category]. The user has the option of leaving the [First
Name] and [Last Name] fields blank and entering a [category]. If the user
leaves [First Name] and [Last Name] blank and enters a [category], the user
needs to get an error message if the [category] does not match any records in
the database.

While most of this may seem trivial and unneccessary, the users of this
database are visually impaired (blind) and therefore will have a harder time
knowing whether the information they have typed in is incorrect. I am trying
to develop the error message to alert them prior to printing that the
information they have entered will result in the printing of a blank *** of
paper.

Thank you very much for your help.

"Steve Schapel" wrote:

Risikio,

"" is not blank. It is a zero-length string, or empty string. This
is not the same as Null. Also, assuming your macro is happening on an
event on the Criteria form, you do not need the Forms! reference. So...
[First Name] Is Null And [Last Name] Is Null And [Category] Is Null

As regards your main question, I am not 100% clear on your meaning. You
mean if the user enters "James", and there is no record at all anywhere
in the table for "James"? Or does this apply to a specific record? If
so, how do you know which record? Can you give some further examples
please?

--
Steve Schapel, Microsoft Access MVP

Risikio wrote:
I am trying to write a macro that will bring up an error message if the data
entered on a form does not match the data already entered into the database.
I know I have to use the MsgBox arguement, but I am having trouble with the
condition.

As an example, if the user enters "James" into the First Name field on the
the form, but the database record has "Jim", I need the error message to
alert the user that the data does not match. The form has three separate
fields that will require this error message [First Name], [Last Name], and
[Category].

I also have a fourth error message if all three of those fields are left
blank. The condition for the fourth error message follows, but it does not
work.

[Forms]![criteria]![First Name]="" AND [Forms]![criteria]![Last Name]="" AND
[Forms]![criteria]![Category]=""

Nothing happens for this fourth error message when I test the form leaving
the three fields blank.

Any help would be appreciated. I am not very good with macros yet.

.