If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Require fields
I have a field call p structure which is a dropdown and one call p revised
date. When some one makes a selection on the p structure field i would like the p revised date field to be a require field. How can i do it? |
#2
|
|||
|
|||
Require fields
Assuming you are using a form for data entry (you should be)
and not working directly in the table (you shouldn't be), you would use code like the following in the Before Update event of the form (substitute your actual control names); Private Sub Form_BeforeUpdate(Cancel As Integer) If Not IsNull(Me![p structure]) Then If IsNull(Me![p revised]) Then MsgBox "Please enter a Revised Date" Cancel = True End If End If End Sub -- _________ Sean Bailey "Jessica" wrote: I have a field call p structure which is a dropdown and one call p revised date. When some one makes a selection on the p structure field i would like the p revised date field to be a require field. How can i do it? |
#3
|
|||
|
|||
Require fields
In a form (it cannot be done in a table) a bit of code something like
(untested) Private Sub p_structure_AfterUpdate() If Len(Me.[p structure] & vbNullString) 0 Then MsgBox "You must fill in p revised date", vbOKOnly, "Required" Me.[p revised date].SetFocus End If End Sub and then: Private Sub Form_BeforeUpdate(Cancel As Integer) If Len(Me.[p structure] & vbNullString) 0 and If Len(Me.[p revised date] & vbNullString) = 0 Then MsgBox "The date in p revised date is REQUIRED" Cancel = True End If End Sub Now they must either delete the data in p structure or add the data in p revised date. -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.mvps.org/access http://www.accessmvp.com "Jessica" wrote in message ... I have a field call p structure which is a dropdown and one call p revised date. When some one makes a selection on the p structure field i would like the p revised date field to be a require field. How can i do it? |
#4
|
|||
|
|||
Require fields
Hi Jessica,
If you want to do it in the table you could use the table-level Validation Rule property (right-click the table window while in design mode and choose Properties). Set it to: (IsNull([p structure]) And IsNull([p revised])) Or (Not IsNull([p structure]) And Not IsNull([p revised])) This assumes that if [p structure] is null [p revised] should be null also. If that is not the case and you allow [p structure] to be null while [p revised] is not null then use: IsNull([p structure]) Or (Not IsNull([p structure]) And Not IsNull([p revised])) You can use the Validation Text property to provide a meaningful message. Clifford Bass "Jessica" wrote: I have a field call p structure which is a dropdown and one call p revised date. When some one makes a selection on the p structure field i would like the p revised date field to be a require field. How can i do it? |
#5
|
|||
|
|||
Require fields
if i already have the below for another field can i have two event procedures?
Private Sub Form_BeforeUpdate(Cancel As Integer) If Not IsNull(Me![Closing Date]) Then If Nz(Me![Exit Reason], "") = "" Then MsgBox " You must choose an exit reason" Cancel = True Me![Exit Reason].SetFocus End If End If End Sub "Beetle" wrote: Assuming you are using a form for data entry (you should be) and not working directly in the table (you shouldn't be), you would use code like the following in the Before Update event of the form (substitute your actual control names); Private Sub Form_BeforeUpdate(Cancel As Integer) If Not IsNull(Me![p structure]) Then If IsNull(Me![p revised]) Then MsgBox "Please enter a Revised Date" Cancel = True End If End If End Sub -- _________ Sean Bailey "Jessica" wrote: I have a field call p structure which is a dropdown and one call p revised date. When some one makes a selection on the p structure field i would like the p revised date field to be a require field. How can i do it? |
#6
|
|||
|
|||
Require fields
On Wed, 8 Jul 2009 07:31:01 -0700, Jessica
wrote: if i already have the below for another field can i have two event procedures? Private Sub Form_BeforeUpdate(Cancel As Integer) If Not IsNull(Me![Closing Date]) Then If Nz(Me![Exit Reason], "") = "" Then MsgBox " You must choose an exit reason" Cancel = True Me![Exit Reason].SetFocus End If End If End Sub The Form can have only one BeforeUpdate event, but that event can check any number of controls. -- John W. Vinson [MVP] |
Thread Tools | |
Display Modes | |
|
|