field must have an entry

Richio

Registered User.
Local time
Today, 22:25
Joined
May 31, 2002
Messages
75
I have a "purchase order" form which is based on related tables and including a subform for products.

A purchase order report is based on the form with a preview button on the from.

It all works fine if all the fields on the form are completed. However if fields on the form are left blank then I keep coming up with

1. Error messages - ie suppliers must have a related record
2. the whole of the report is blank even if only one feld is missed off
3. VB debug codes

Is there anyway that I can ensure that a user must make an entry in all fields on the form so if on previewing the report it states for example "please enter a supplier / employee / delivery date (whichever) is blank" or even a general "not all fields on the form have been correctly complted" comment

Many thanks
 
Hi Richio

Couple of ways to do this.

In the table design you can set the "Required" property of the fields to Yes.

or

You can write some code OnExit of the fields to check that it is not null. If it is null then you can have a message box come up to say so.

or

In the OnClick of the PrintPreview you can have the code there to check if the fields are null and if they are you can have a msgeBox then have the curser go back to the offending field(s)

Post if you need help with any code. I can knock something up for you if it helps.

Col
 
Colin

thanks for the reply...your last option is the one I have had in mind (and would be the most professional).

I have had a go with the On no data on opening the report, but if you could point me in the right direction of the code for OnClick of the print preview it would be greatly appreciated

Richio
 
I suggest you use a command button on the form. Then you can go into properties - OnClick. The wizard will have put some code there already for the print preview so before that code you need to put something like

If IsNull(Me.FieldName) Then
MsgBox "Not all fields have been completed, cannot procede"
DoCmd.GotoControl "FieldName"
End If

I may have the syntax a little wrong as I am doing it from memory which is failing at this time of day!!! But I'm sure I'm fairly close.

Col
 
Definitely helping - but after the message box it still takes me to the report preview.

Can the report preview be cancelled somehow?

Sorry to be a pain

Richio
 
Ok

now worked it out, one last question though

I have at present
If IsNull(Me.Employee) Then
MsgBox "Enter employee name"
DoCmd.GoToControl "Employee"

Else

If I also want to include other fields not to be Null I am entering all the same code again but with "Reason Code" for example

Is there a way I can enter it as

If IsNull (All the fields I want it to go through) Then
MsgBox "A mandatory field has not been completed"

this would make my code alot simpler

Thanks again
 

Users who are viewing this thread

Back
Top Bottom