Results 1 to 5 of 5
  1. #1
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63

    Making a field required based on the value of another field

    Good morning,

    I have a form with the following:

    Combobox (1b Answer) - User can only either select 'Yes' or 'No'
    Textbox (1b Comments) - User can enter freeform notes
    Combobox (Save_or_Submit) - User can only either select 'Save' or 'Submit'
    Command Button (CloseButton) - Information is saved to the table


    What I want to happen is the following:

    Save_or_Submit is a required field. When the user selects 'Save', the information is saved into the table (no required fields). When the user selects 'Submit', 1b Comments is required only when 1b Answer is answered 'Yes'.


    This is what I have so far:

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Me.Save_or_Submit = "Submit" Then
    If Me.[1b Answer] = "Yes" Then
    If IsNull(Me.[1b Comments]) Or Me.[1b Comments] = "" Then
    MsgBox "You must enter a comment for question 1b."
    Cancel = True
    Exit Sub
    End If
    End If
    End If
    End Sub


    Private Sub CloseButton_Click()
    If MsgBox("Changes have been made to this record." _
    & vbCrLf & vbCrLf & "Do you want to save these changes?" _


    , vbYesNo, "Changes Made") = vbYes Then
    DoCmd.Save
    Else
    DoCmd.RunCommand acCmdUndo
    End If
    DoCmd.Close acForm, "Functional Risk Profile", acSaveNo
    End Sub

    Please help! I cannot get this to work!

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    You probably should check the Combobox (Save_or_Submit).

    Sub NameOfCombo_afterupdate()
    If Me.Save_or_Submit = "Submit" Then
    If Me.[1b Answer] = "Yes" Then
    If IsNull(Me.[1b Comments]) Or Me.[1b Comments] = "" Then
    MsgBox "You must enter a comment for question 1b."
    Cancel = True
    Exit Sub
    End If
    End If
    End If
    End Sub

  3. #3
    thexxvi is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    May 2015
    Posts
    63
    any other away you can think of? I don't want what will be perceived as an error message popping up every time someone selects yes (there are really 37 questions).

  4. #4
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Quote Originally Posted by thexxvi View Post
    Save_or_Submit is a required field. When the user selects 'Save', the information is saved into the table (no required fields). When the user selects 'Submit', 1b Comments is required only when 1b Answer is answered 'Yes'.
    The code will check as you stated.

    Unless I misunderstood something or I don't understand what you are asking for or what you are trying to do.

  5. #5
    cbende2's Avatar
    cbende2 is offline Competent Performer
    Windows 7 32bit Access 2013
    Join Date
    Jun 2014
    Location
    Louisiana
    Posts
    370
    thexxvi, run a forloop, You will want it checking all 37 questions. It will then prompt the users with one(s) they miss. This is good.

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

Similar Threads

  1. Replies: 10
    Last Post: 06-18-2015, 11:52 AM
  2. Replies: 3
    Last Post: 08-07-2014, 08:48 AM
  3. Replies: 1
    Last Post: 07-16-2014, 10:05 AM
  4. Replies: 1
    Last Post: 12-07-2012, 02:14 AM
  5. Replies: 3
    Last Post: 01-15-2012, 02:46 PM

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