Solved

data validation

Posted on 1998-10-02
4
143 Views
Last Modified: 2010-04-30
How do you return focus to a control when not updating data?
0
Comment
Question by:shakenbake
  • 2
4 Comments
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1437886
use this example:

Private Sub cmdCancel_Click()

Text1.SetFocus
End Sub


if the user choose to cancel in this case then it return focus to the text1 box (Enter First name ) for example.

If you need more help post or email to shayplace@hotmail.com


0
 

Author Comment

by:shakenbake
ID: 1437887
I didn't explain my problem well enough.
0
 

Author Comment

by:shakenbake
ID: 1437888
When adding a new record, and entering a new field such as LastName, is there any way to prevent the user from moving to another control if they don't enter a value for "LastName".  What I'd like to see happen is :
1) if the user has not entered a last name, display a msg warning them that name cannot be blank;
2) put the cursor back into the LastName control (This is the part I'm having trouble with. LastName.SetFocus won't work in, say, LastName_LostFocus event. It will work in LastName_Update event, but in my context I am NOT updating data. LastName is already blank and the user skips thru LastName without entering data so there is no update. I don't want them to skip thru LastName without entering anything. My question is how do you put them back to the LastName control?  Sorry for the verbosity.

0
 
LVL 12

Accepted Solution

by:
gbzhhu earned 50 total points
ID: 1437889
Try this it worked for me before.

On every data entry control (textboxes etc) on your form add this in their KeyPress events

Sub Check_LastName(key As Integer)
    If LastName.Text = "" Then
        key = 0
        MsgBox "Must enter last name"
        LastName.SetFocus
    End If
End Sub


Call this procedure like this

Check_LasName KeyAscii

What it does is that it takes the key pressed by the user and sees if lastname is empty, if so it ignores the key and displays the message and sends the focus to LastName  (I assumed LastName is a textbox)

Hope this helps
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

839 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