Results 1 to 3 of 3
  1. #1
    AussieGal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    56

    If combo box is certain answer then make another field required

    Hi,

    I have a combo box (OsubAbuse) on a form that allows uses to select Yes, no or unknown (1, 2 or 3). I want it so that if they select yes (2) in the combo, the next field ODignosis is required to have something entered into it and not left blank.

    I have a botton on the form they must press to get the report they need to print, but I already have code in there, so I am not sure how the new code would fit in there although it seems that this would be the best place to put it.
    Below is the existing code on the button (which as well as beeps, brings up a message box for other fields that are required which is called from another module)


    Code:
    Option Compare Database
    Option Explicit
    Private Sub cmdPrintEpisodeForm_Click()
    If validateform(Me) Then
        DoCmd.RunCommand acCmdSaveRecord
        DoCmd.Minimize
        DoCmd.OpenReport "rptEpisodeSummaryPrintable", acViewPreview, , "EpisodeID = " & Me.EpisodeID
    Else: DoCmd.Beep
    End If
    End Sub
    Hoping someone can help. Thanks in advance
    Last edited by June7; 03-28-2013 at 02:18 AM. Reason: fix code for readability

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Something like:

    If Me.OsubAbuse = 2 And IsNull(Me.ODiagnosis) Then
    MsgBox "Must enter diagnosis."
    ElseIf validateform(Me) Then
    ...

    Is validateform a custom function? The Me reference might error. Try: Me.Name
    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
    AussieGal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    56
    This works great. Thank you. I knew it was something simple. ValidateForm is a custom function I have not had any issues yet. What it does is checks that all required fields on the form are compelete.
    I have pasted it for reference:
    Code:
    Option Compare Database
    Public Function validateform(myform As Form) As Boolean
    'returns true if all required fields have data, or false if not.
    'It will also create a popup message explaining which fields need data
    Dim boolresponse As Boolean
    Dim strError As Variant
    Dim ctl As Control
    boolresponse = True
    strError = Null
    With myform
        For Each ctl In .Controls
          With ctl
            If .Tag = "required" Then
               If .Value & "" = "" Then
                    boolresponse = False
                    strError = (strError + ", ") & .Name
                End If
            End If
          End With
        Next ctl
    End With
    If strError & "" <> "" Then MsgBox "The following information must be entered first: " & strError, vbInformation
    validateform = boolresponse
    End Function
    Thanks so much for your response.

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

Similar Threads

  1. Replies: 11
    Last Post: 01-28-2013, 12:11 PM
  2. Replies: 1
    Last Post: 12-07-2012, 02:14 AM
  3. Answer abuot Combo Box
    By mojahed.mroteza in forum Access
    Replies: 5
    Last Post: 07-14-2012, 11:18 AM
  4. Make new field based on previous field's answer
    By VictoriaAlbert in forum Access
    Replies: 1
    Last Post: 04-11-2011, 09:54 PM
  5. Replies: 1
    Last Post: 09-09-2010, 04:40 PM

Tags for this Thread

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