Solved

data validation

Posted on 1998-10-02
4
139 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

708 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

20 Experts available now in Live!

Get 1:1 Help Now