Results 1 to 3 of 3
  1. #1
    BrittKnee is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2020
    Posts
    17

    Setting a Required Field in a Subform

    Hi All!

    I am trying to set a required field in a subform (datasheet view) upon exiting the main form. I have a save/close button which I have coded to require other fields within the main form, so I am familiar with how to require fields. I am just unsure on how to reference the subform field.

    Main Form: Edit_Invoice
    Subform: Create_Payment


    Subform Field: Amount_Paid

    Below is the current code I have on click for the save/close button There are no issues with the required fields from the main form, just adding the subform's field as required. Thanks!

    Code:
    Private Sub Command459_Click()
    
    
    If IsNull(Me.cbo_ClientName) Then
        MsgBox "PLEASE INSERT CLIENT NAME", vbExclamation, "DATA REQUIRED!"
        Me.cbo_ClientName.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Combo482) Then
        MsgBox "PLEASE ENTER SOC ACTIVE/INACTIVE", vbExclamation, "DATA REQUIRED!"
        Me.Combo482.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Text423) Then
        MsgBox "PLEASE ENTER SOC DATE", vbExclamation, "DATA REQUIRED!"
        Me.Text423.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Text479) Then
        MsgBox "PLEASE ENTER PAYMENT DUE DATE", vbExclamation, "DATA REQUIRED!"
        Me.Text479.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Combo701) Then
        MsgBox "PLEASE ENTER TOLLS OWED", vbExclamation, "DATA REQUIRED!"
        Me.Combo701.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Combo702) Then
        MsgBox "PLEASE ENTER FEES OWED", vbExclamation, "DATA REQUIRED!"
        Me.Combo702.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Text491) Then
        MsgBox "PLEASE ENTER TOLLS REMOVED", vbExclamation, "DATA REQUIRED!"
        Me.Text491.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Text493) Then
        MsgBox "PLEASE ENTER FEES REMOVED", vbExclamation, "DATA REQUIRED!"
        Me.Text493.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Combo810) Then
        MsgBox "PLEASE ENTER % FEE DISCOUNT", vbExclamation, "DATA REQUIRED!"
        Me.Combo810.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Text455) Then
        MsgBox "PLEASE ENTER VCD RUN DATE", vbExclamation, "DATA REQUIRED!"
        Me.Text455.SetFocus
    Exit Sub
    End If
    
    
    
    
    If IsNull(Me.Text443) Then
        MsgBox "PLEASE ENTER VIOLATION START DATE", vbExclamation, "DATA REQUIRED!"
        Me.Text443.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Text444) Then
        MsgBox "PLEASE ENTER VIOLATION END DATE", vbExclamation, "DATA REQUIRED!"
        Me.Text444.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Text453) Then
        MsgBox "PLEASE ENTER NUMBER OF VIOLATIONS", vbExclamation, "DATA REQUIRED!"
        Me.Text453.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Combo703) Then
        MsgBox "PLEASE ENTER SOC CONTACT NAME", vbExclamation, "DATA REQUIRED!"
        Me.Combo703.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Combo704) Then
        MsgBox "PLEASE ENTER SOC CONTACT PHONE NUMBER", vbExclamation, "DATA REQUIRED!"
        Me.Combo704.SetFocus
    Exit Sub
    End If
    
    
    If IsNull(Me.Combo705) Then
        MsgBox "PLEASE ENTER SOC CONTACT E-MAIL", vbExclamation, "DATA REQUIRED!"
        Me.Combo705.SetFocus
    Exit Sub
    End If
    
    
    If Forms!Master_ManAcc_Form_EDIT_Invoice_Data!SubForm.Payment_History_subform!Payment_Type <> "" Then
        MsgBox "PLEASE ENTER PAYMENT TYPE"
        Forms!Master_ManAcc_Form_EDIT_Invoice_Data!SubForm.Payment_History_subform!Payment_Type.SetFocus
    Exit Sub
    End If
         
    DoCmd.Close
    DoCmd.OpenForm "frmAdvancedSearch_Edit_Invoice_Data"
    End Sub

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Why don't you have validation code for subform behind the subform?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    I'm just going to assume you have a valid reason for not putting validation code behind the subform and say that the syntax is

    [Forms]![Main form name]![subform control name].[Form]![control name on subform]

    You ought to give objects meaningful names - you will find such code difficult to troubleshoot down the road, and anyone who has to follow you and knows better won't appreciate that style very much.

    When (if) your users complain about having to deal with these prompts 1 by 1, consider amalgamating all missing field names into 1 message.

    EDIT - forgot to mention that I agree that the code belongs on the form it's meant to control. Also, if your form is bound, you realize that by leaving a record you will commit it or any changes made to it? A save button on a bound form is usually somewhat useless and might create unexpected results.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 07-07-2020, 10:35 AM
  2. Replies: 5
    Last Post: 08-14-2018, 11:59 AM
  3. Required fields in subform
    By Ray67 in forum Forms
    Replies: 3
    Last Post: 12-13-2012, 06:35 AM
  4. Replies: 5
    Last Post: 10-08-2011, 05:19 AM
  5. Replies: 2
    Last Post: 09-12-2011, 11:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums