Solved

How stop routine if text field is left blank

Posted on 2012-04-13
3
304 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Some sers suddenly getting error popup msg 28 89
Access 2016 7 35
Create macro from runcode 30 26
Dirty form - conditional formatting 5 27
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

809 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