Form validation rule

cinders

Registered User.
Local time
Today, 16:26
Joined
Aug 28, 2001
Messages
48
I have a databse built to use as a survey tool. The survey is to remain annoymous so I have built an ID table with some random id numbers that will be distributed in envelopes. I have tables built on areas and in those tables I have the various questions and ratings built in.

I have a query built to prompt the user for their user code. I have done this to eliminate them looking at other users entries and being influenced by the way someone else has answered.

I have 22 predetermined user id's. When a user is prompted to enter the user id I want the system to validate that user id before taking them into the form. If the user id does not exist in the table I would like an error message returned. How do I accomplish this?

Thanks
 
When the user enters their id either code or a macro runs to open a form/report that shows their details, am I right?

If so, use either a macro with a condition or an If ... Then ... statement in your code.

In both instances if the record count = 0 it means the users code is not found (no records)and a message box can appear to that effect. If more than one record is found it means the id is correct and the code or macro can pass the user on to the form or report.

The macro conditions should look something like:

DCount("*","TableName","[FieldName]=Forms![FormName]![FieldName]")>0
(If there is more than 1 record found open form/report action).

DCount("*","TableName","[FieldName]=Forms![FormName]![FieldName]")=0
(If there are no records found message box action).

If you want to do this using code first create the macro and then convert the macro into code (see options in the Tools menu).

I hope this is useful.
 
Acutally my form is a Parent and Child form. The Parent form holds the user is and the subform holds the detail. The Parent form is based on a query that prompts the user to enter their id.

So how can I work the macro into this scenario or do I have to write a macro as well to prompt the user for their id?

Thanks for the help, it is great. Any more suggestions you can pass along are highly appreciated.
 
In the above expression the [FormName] refers to the parent form. The child form will follow the parent form.

The macro should do the following:
> Open the form based on the criteria the user gives. (I would get the user type their id in an unbound field on an unbound form).
> Run the above conditions to open the form if the id is correct and to give a message if the id is incorrect.
 

Users who are viewing this thread

Back
Top Bottom