Solved

How stop routine if text field is left blank

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

737 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