?
Solved

How stop routine if text field is left blank

Posted on 2012-04-13
3
Medium Priority
?
310 Views
Last Modified: 2012-04-13
I have a form which contains a command button.  Also on this form is a text field.  When the command button is clicked and if the text field is left blank I want the routine to stop and make the user enter a value in the text field.  Here is my attempt...

    If Me.txtPOn = "" Then
        MsgBox "You must enter a PO number first!"
        Me.txtPOn.SetFocus
    End If

But what is happening is the record is getting written to the table because of code after the above code.  This is not what I want to have happen.  Instead, the whole routine should halt and the focus should be on the text box.. "txtPOn".

I can't figure out how to make this happen.  Can someone help?

--Steve
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 48

Expert Comment

by:Dale Fye
ID: 37842256
Steve,

It is likely that if no data has ever been entered into the txtPOn control, that the "value" of that control is NULL, and whenever you try to compare a NULL to anything, it will fail, so you should either use:

IF me.txtPOn & "" = "" Then

or you could use

If NZ(me.txtPOn, "") = "" Then
0
 
LVL 17

Accepted Solution

by:
Natchiket earned 2000 total points
ID: 37842281
You need to exit the procedure rather than carrying on with the code, thus

If Nz(Me.txtPOn,vbNullstring) = vbNullstring Then
        MsgBox "You must enter a PO number first!"
        Me.txtPOn.SetFocus
        Exit Sub
End If
0
 

Author Closing Comment

by:SteveL13
ID: 37842351
This worked perfectly.  Thank you for your help.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question