Solved

data validation

Posted on 1998-10-02
4
145 Views
Last Modified: 2010-04-30
How do you return focus to a control when not updating data?
0
Comment
Question by:shakenbake
[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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

752 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