i am having a problem with validation, everytime i want to check to see if the filed has an empty value before adding. the problem is that i get the error message saying the control must have focus. in my if statement i have more than one field to check.
how can i set focus to more than one field, or is there another way.
if txtLName.text = "" then
msgbox("Please enter a last name")
the problem comes with checking for multiple fields.
i know the code but the error keeps coming up saying control needs to have focus
i will try the method that you showed me
You get the error message because in if txtLName.text = "" you have an assignment statement embedded in an if statement. This is the same as if you write:
if (txtLName.text = "") Then
Access tries first to assign "" to the txtLName.Text property. If you want to know what is contained in the the text box, you should use:
if txtLName.Value = "" Then
if txtLName = "" Then
Yes, I know, it is confusing :-)) One more trap: if the user doesn't type anything in an Access text box, its value is not an empty string, but Null. That is why the safest way to check blank fields is:
if Trim(txtLName.Value & "") = "" Then
It covers the cases when the field contains nothing, an empty string or only spaces. Watch for joking users that type only Tabs or other non-printable characters :-))