Solved

data validation

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 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

16 Experts available now in Live!

Get 1:1 Help Now