469,326 Members | 1,588 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

How to check for empty string?

Hi,
I am very new to access. I am asking something basic.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command12_Click()
  2.     Dim strAbc As String
  3.     strAbc = "a"
  4.     MsgBox IsNull(strAbc)
  5.     MsgBox IsEmpty(strAbc)
  6. End Sub
How to check if variable strAbc has a value/is not an empty string? I tried isNull and isEmpty and both returns false whether strAbc is assigned "" or "a".

Thanks,
Robin
Aug 16 '10 #1

✓ answered by NeoPa

Robin, It's important to know what you are dealing with when making such a check. As yours clearly states it is a string variable, then the correct way to check it would be as Mike has suggested - (strABC = "").

On the other hand, form controls are objects that may contain Null. Checking form controls should be done using IsNull() instead - (IsNull(Me.txtABC)). Controls with no data entered are never empty strings. Nz() may be used for simplifying usage of the control's value, but is not a good way to test if anything has been entered.

3 82788
MikeTheBike
637 Expert 512MB
Hi

You could try this

MsgBox strAbc <> ""

??

MTB
Aug 17 '10 #2
munkee
374 256MB
I use the following to check for null and zero length string of a control. Just replace control for your string variable.

Expand|Select|Wrap|Line Numbers
  1. Len(Nz(Me.controlname, "")) = 0
or you can just use the straight
Expand|Select|Wrap|Line Numbers
  1. len(string) < 1
Aug 17 '10 #3
NeoPa
32,180 Expert Mod 16PB
Robin, It's important to know what you are dealing with when making such a check. As yours clearly states it is a string variable, then the correct way to check it would be as Mike has suggested - (strABC = "").

On the other hand, form controls are objects that may contain Null. Checking form controls should be done using IsNull() instead - (IsNull(Me.txtABC)). Controls with no data entered are never empty strings. Nz() may be used for simplifying usage of the control's value, but is not a good way to test if anything has been entered.
Aug 17 '10 #4

Post your reply

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

Similar topics

6 posts views Thread by Chris Connett | last post: by
11 posts views Thread by Dan Bass | last post: by
21 posts views Thread by M D | last post: by
3 posts views Thread by Adam Knight | last post: by
5 posts views Thread by Tan | last post: by
2 posts views Thread by shapper | last post: by
7 posts views Thread by tomlebold | last post: by
4 posts views Thread by Jay | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Gurmeet2796 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.