Solved

data validation

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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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 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 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…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

628 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