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
|
|||
|
|||
Requiring Data in a field based on another field's entry
I have two fields on a form: NCR_No and Insp_Date. I want to make it so if a user enters an NCR_No, an error message appears if the user did not enter an Insp_Date telling them an Insp_Date is required.
How can I accomplish this? Jeff |
#2
|
|||
|
|||
Requiring Data in a field based on another field's entry
"Jeff Monroe" wrote in message
... I have two fields on a form: NCR_No and Insp_Date. I want to make it so if a user enters an NCR_No, an error message appears if the user did not enter an Insp_Date telling them an Insp_Date is required. Solution A: Validation Rule on the Table ============================= Use this if the user *must* always enter a date if NCR_No is entered. 1. Open your table in design view. 2. Open the Properties box (View menu.) 3. Beside the Validation Rule in the Properties box, enter: ([NCR_No] Is Null) OR ([Insp_Date] Is Not Null) Be sure to use the rule in the Properties box, not the one in the lower pane of table design (which applies to one field.) 4. Enter the message you want in the Validation Text property, e.g.: You must enter the Inspection Date if you enter an NCR Number. More about validation rules: http://allenbrowne.com/ValidationRule.html Solution B: BeforeUpdate event procedure of the form ====================================== Use this to give a warning, but let the user override it. 1. Open the Form in design view. 2. Set the Before Update property of the *form* (not of a text box) to: [Event Procedure] 3. Click the Build button (...) beside the property. Acess opens the code window. 4. Set up the event procedure like this: Private Sub Form_BeforeUpdate(Cancel As Integer) Dim strMsg As String If IsNull(Me.[Insp_Date]) And Not IsNull(Me.[NCR_No]) Then strMsg = "NCR number, but no inspection date." & vbCrLf & _ "Continue anyway?" If MsgBox(strMsg, vbYesNo + vbDefaultButton2, _ "Are you sure?") = vbNo Then Cancel = True 'Me.Undo End If End If End Sub Solution C: Automatically enter the date ============================= Use the After Update event procedure of NCR_No to assign today's date to the Insp_Date: If IsNull(Me.[Insp_Date]) And Not IsNull(Me.[NCR_No]) Then Me.[Insp_Date] = Date End If You probably want to use Solution A or B as well. -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. |
Thread Tools | |
Display Modes | |
|
|