By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,608 Members | 1,925 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,608 IT Pros & Developers. It's quick & easy.

warning message if field is left blank

P: 2
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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2.  
  3.     nullerr = 0
  4.     strnull = ""
  5.  
  6.     If IsNull(Me.txtQuestion) Then
  7.         nullerr = 1
  8.         strnull = "Questions " & vbNewLine
  9.     End If
  10.  
  11.     If IsNull(Me.txtAuthor) Then
  12.         nullerr = 1
  13.         strnull = strnull & "Author " & vbNewLine
  14.     End If
  15.  
  16.     If IsNull(Me.comboType) Then
  17.         nullerr = 1
  18.         strnull = strnull & "Type " & vbNewLine
  19.     End If
  20.  
  21.     If IsNull(Me.toggleA) Or IsNull(Me.toggleB) Or IsNull(Me.toggleC) Or IsNull(Me.toggleD) Then
  22.         nullerr = 1
  23.         strnull = strnull & "Answer"
  24.     End If
  25.  
  26.     If nullerr Then
  27.         MsgBox "These fields cannot be left blank: " & vbNewLine & strnull
  28.         DoCmd.RunCommand acCmdUndo
  29.     End If
  30.  

Attached Images
File Type: jpg help2.jpg (31.1 KB, 1004 views)
Apr 10 '14 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,240
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
Apr 10 '14 #2

Expert 100+
P: 1,240
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
Apr 10 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.