Required Field

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All...I have three fields that I would like end users to enter before
closing the form. I have following code

If IsNull(Me.tblClient_ClientName) Then
MsgBox "Missing Client Name", vbCritical, msgTitle
Me.tblClient_ClientName.SetFocus


ElseIf IsNull(Me.tblClient_CID) Then
MsgBox "Missing Client CID", vbCritical, msgTitle
Me.tblClient_CID.SetFocus


ElseIf IsNull(Me.tblClient_Product) Then
MsgBox "Missing Client Product", vbCritical, msgTitle
Me.tblClient_Product.SetFocus

end if

Now when there is not value in any of the three fields, the system does give
an error and sets the focus on Client Name. Once I provide the client name
then it stops at Client CID. Now, if I erase the client name it still accepts
the null value and doesn't give error message. I know I can fix this by
setting the field property to required in table; however, I don't want to do
that. What is the easy way I can always loop through to make sure they have
not erased the data after entering it once they get the error message.

Thanks.
 
Hi Mikey,

Maybe you can try something like this:

If nz(Me.tblClient_ClientName,"") ="" Then
MsgBox "Missing Client Name", vbCritical, msgTitle
Me.tblClient_ClientName.SetFocus


ElseIf nz(Me.tblClient_CID,"")="" Then
MsgBox "Missing Client CID", vbCritical, msgTitle
Me.tblClient_CID.SetFocus


ElseIf nz(Me.tblClient_Product,"")="" Then
MsgBox "Missing Client Product", vbCritical, msgTitle
Me.tblClient_Product.SetFocus

end if


Cheers....

Yeroon
 
Hey Mikey,

Try changing your IsNull to this and see if takes care of your problem:

If Trim(Nz(Me.tblClient_ClientName,"")) = "" Then

This will check for Null and an empty string. I think the empty string is
what's causing your problems.

HTH,
Shane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top