Solved

How stop routine if text field is left blank

Posted on 2012-04-13
3
301 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
3 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
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 500 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

758 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now