Testing if a textbox is empty in VBA

Luis -  
 swissi -
Hello,

I am currently creating a form in Access.
I have two independent fields named: User and Passwd.
I also have a button labeled OK.
I would like a window to pop up when I click the button if either of the two textboxes is empty.

Here is the code I have:

If User = Null Or Passwd = Null Then
MsgBox "Please enter a username and a password"
End If

But it doesn't work.

A little help would be greatly appreciated please.

Thank you

Luis

8 answers

blux Posted messages 5021 Registration date   Status Moderator Last intervention   3 455
 
Glad to hear that!

Don't forget to also test for the empty value, which is not "null" (if the user starts typing and then deletes...)
If IsNull(User.Value) or User.Value = "" Then...

--
See you later, Blux
 "The fools will try anything. That's how you recognize them."
10
blux Posted messages 5021 Registration date   Status Moderator Last intervention   3 455
 
Hi,

it's normal, null is not tested as a value, but with a function :
If IsNull(User.value)...

--
See you, Blux
 "Stupidity dares everything. That's how we recognize them."
5
Luis
 
Oh yes, I hadn't thought of that...
Thank you
1
Luis
 
It works.

Thank you very much

Luis
0
Luis
 
I just have one last question:

Do you know which font I should use for the textbox containing the password?
So that it only shows black dots...
0
blux Posted messages 5021 Registration date   Status Moderator Last intervention   3 455
 
It's not a police story, but rather a formatting story; you have to choose "password" or "mot de passe," and that's what will display either stars or "black dots"... (data tab of the textbox, field "input mask")...

--
A+ Blux
 "Stupid people dare to do anything. It's even how you recognize them." 
0
Luis
 
Everything's good then

Thank you very much for your help and have a great day

Luis
0
swissi
 
Hello
I'm developing a form and I want to validate the value of a TextBox that must be a non-zero integer

What should I do?
I wrote this but it doesn't work:

Private Sub TextBox1_Change()
Dim KeyAscii As MSForms.ReturnInteger
Select Case KeyAscii
Case Is < 49, Is > 57
MsgBox "Only a non-zero integer is allowed."
KeyAscii = Asc(Chr(8))
End Select

End Sub
0