Dependant and required fields

J

jk

Hi
I have a form in which one field called invoice is dependant on the field
amount being entered.I also have code field that sometimes the user skips all
together.A)How do you have a message prompt or flag user that an amount must
be made if the invoice has been filled .B)How do you prevent the record being
saved if the code field is left blank? I have tried required in the table for
the code field but the error message is too generic.
Thanks
 
S

Sheila D

Can you set a validation rule - i.e >0. If so then you can also set the
validation text property to display your own message.

Hope this helps

Sheila
 
A

Allen Browne

Use the BeforeUpdate event procedure of the form (not that of the control):

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Isnull(Me.[Amount]) Then
Cancel = True
MsgBox "You must fill in the Amount
Me.Amount.SetFocus
End If
End Sub
 
J

jk

Thanks Allen,
I dont think i am doing this correctly...these statements are for the before
update on form??This is part of the SQL on the form...
SELECT [InvoiceDetails1].[InvNum], , [InvoiceDetails1].[AdjAmt]....the code
will prevent the user from entering the record if the Invoice field is
populated????Could you advise to what i am doing wrong....thanks

Allen Browne said:
Use the BeforeUpdate event procedure of the form (not that of the control):

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Isnull(Me.[Amount]) Then
Cancel = True
MsgBox "You must fill in the Amount
Me.Amount.SetFocus
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

jk said:
I have a form in which one field called invoice is dependant on the field
amount being entered.I also have code field that sometimes the user skips
all
together.A)How do you have a message prompt or flag user that an amount
must
be made if the invoice has been filled .B)How do you prevent the record
being
saved if the code field is left blank? I have tried required in the table
for
the code field but the error message is too generic.
Thanks
 
A

Allen Browne

1. Open your form in design view.

2. Open the Properties box (View menu).

3. Make sure the title of the Properties box says "Form", not some control
or section.

4. On the Event tab, locate the Before Update property, and set to:
[Event Procedure]

5. Click the Build button (...) beside the property.
Access opens the code window.

6. Make the event procedure look like the example.

Access fires the BeforeUpdate event of the *form* immediately before it
saves the record. If you cancel the event, the record does not get saved.

The Form_BeforeUpdate does not normally contain a SELECT query statement.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

jk said:
Thanks Allen,
I dont think i am doing this correctly...these statements are for the
before
update on form??This is part of the SQL on the form...
SELECT [InvoiceDetails1].[InvNum], , [InvoiceDetails1].[AdjAmt]....the
code
will prevent the user from entering the record if the Invoice field is
populated????Could you advise to what i am doing wrong....thanks

Allen Browne said:
Use the BeforeUpdate event procedure of the form (not that of the
control):

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Isnull(Me.[Amount]) Then
Cancel = True
MsgBox "You must fill in the Amount
Me.Amount.SetFocus
End If
End Sub


jk said:
I have a form in which one field called invoice is dependant on the
field
amount being entered.I also have code field that sometimes the user
skips
all
together.A)How do you have a message prompt or flag user that an amount
must
be made if the invoice has been filled .B)How do you prevent the record
being
saved if the code field is left blank? I have tried required in the
table
for
the code field but the error message is too generic.
Thanks
 
J

jk

Thanks Sheila,

Is the validation rule set on the control of the form on on the field within
the table?
Thanks
 
Top