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

Verify if a text box = 0 is has nothing in it?

P: 8
I am trying to verify if a text box is equal to 0 or is blank before the close button is pushed. The code works if the box equals 0 but not if it is blank. Can anyone help me with this. Here is the code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command33_Click()
  2. UnusedHRS.SetFocus
  3. If UnusedHRS = 0 Or UnusedHRS = Null Then
  4.     DoCmd.Close
  5. ElseIf UnusedHRS <> 0 Then
  6.     MsgBox "There are still hours that are unaccounted for", vbInformation, "Staffmark"
  7.     End If
  8. End Sub
Jul 4 '10 #1

✓ answered by Jerry Maiapu

If I can understand you properly then try this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command33_Click()
  2.  If Me.UnusedHRS = 0 Or IsNull(Me.UnusedHRS) = True Then
  3.   DoCmd.Close
  4.    Else
  5.        MsgBox "There are still hours that are unaccounted for", vbInformation, "Staffmark"
  6. Me.UnusedHRS.SetFocus
  7.     End If
  8.  End Sub
  9.  
If still not working replace
Expand|Select|Wrap|Line Numbers
  1. IsNull(Me.UnusedHRS)=True
in line#2 with
Expand|Select|Wrap|Line Numbers
  1. Me.UnusedHRS)=" "
Cheers..Hope this helps. Note: Using "Me" makes the code run faster.

Jerry

Share this Question
Share on Google+
4 Replies


Jerry Maiapu
100+
P: 259
If I can understand you properly then try this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command33_Click()
  2.  If Me.UnusedHRS = 0 Or IsNull(Me.UnusedHRS) = True Then
  3.   DoCmd.Close
  4.    Else
  5.        MsgBox "There are still hours that are unaccounted for", vbInformation, "Staffmark"
  6. Me.UnusedHRS.SetFocus
  7.     End If
  8.  End Sub
  9.  
If still not working replace
Expand|Select|Wrap|Line Numbers
  1. IsNull(Me.UnusedHRS)=True
in line#2 with
Expand|Select|Wrap|Line Numbers
  1. Me.UnusedHRS)=" "
Cheers..Hope this helps. Note: Using "Me" makes the code run faster.

Jerry
Jul 5 '10 #2

P: 8
Thanks Jerry, for the help the IsNull() worked perfectly!
Jul 5 '10 #3

Jerry Maiapu
100+
P: 259
Glad I could help

Regards

JM
Jul 5 '10 #4

NeoPa
Expert Mod 15k+
P: 31,768
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command33_Click()
  2.     UnusedHRS.SetFocus
  3.     If Nz(Me.UnusedHRS, 0) = 0 Then
  4.         DoCmd.Close
  5.     Else
  6.         MsgBox "There are still hours that are unaccounted for", vbInformation, "Staffmark"
  7.     End If
  8. End Sub
I would consider putting this code in the Form_Close() event procedure instead. Otherwise the form could be closed another way and it would work fine, thereby leaving hours unaccounted for.

PS. Using IsNull() is also a perfectly reasonable approach. I prefer Nz(), but that's my personal choice.
Jul 5 '10 #5

Post your reply

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