warning message if field is left blank

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • drus
    New Member
    • Apr 2014
    • 2

    warning message if field is left blank

    I have a questions database. When user is filling out the form, the following fields are required: Questions, Author, Type of Question and Answer selected. Answer is selected by clicking on the button next to the Answers. If these fields are not filled out, a user gets a prompt saying that so and so field is blank. If have a problem, it works for all required fields except for Answer. Below is my code. I have attached a screenshot with Author and Answers blank. I only get a warning about the Author and not the Answers.

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
        
        nullerr = 0
        strnull = ""
    
        If IsNull(Me.txtQuestion) Then
            nullerr = 1
            strnull = "Questions " & vbNewLine
        End If
    
        If IsNull(Me.txtAuthor) Then
            nullerr = 1
            strnull = strnull & "Author " & vbNewLine
        End If
    
        If IsNull(Me.comboType) Then
            nullerr = 1
            strnull = strnull & "Type " & vbNewLine
        End If
    
        If IsNull(Me.toggleA) Or IsNull(Me.toggleB) Or IsNull(Me.toggleC) Or IsNull(Me.toggleD) Then
            nullerr = 1
            strnull = strnull & "Answer"
        End If
    
        If nullerr Then
            MsgBox "These fields cannot be left blank: " & vbNewLine & strnull
            DoCmd.RunCommand acCmdUndo
        End If
    [imgnothumb]http://bytes.com/attachment.php? attachmentid=75 81[/imgnothumb]
    Attached Files
    Last edited by zmbd; Apr 11 '14, 12:57 AM. Reason: [z{placed image in line}]
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1288

    #2
    drus,
    I suspect all of your toggle switches have a value, probably defaulted to zero, so they fail the Isnull test.

    You can put all of your toggle switches into one Group box and test only the value of the Group box, instead of testing all 4 of the toggle switches.

    Give each of the 4 toggle switches a value (1-4) and put them in a group box. Set the group box value to zero before any selections are made. The group box will take on the value of the selected toggle switch within the group when one is selected. Conveniently, selecting one deselects all the others.

    Jim

    Comment

    • jimatqsi
      Moderator Top Contributor
      • Oct 2006
      • 1288

      #3
      Ah, now that I see your other question, I realize you already have the group box set up. Very well, just change the way you test the result.

      Jim

      Comment

      Working...