Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SetFocus after Lost Focus

Posted on 2003-11-13
8
Medium Priority
?
516 Views
Last Modified: 2008-03-10
Hi,
I have a function that validates the contents of a field using it's lost focus event. If the contents are invalid, then the focus should be set to the offending field, which seems impossible to do when using the lost focus event. Anyone know a way to do this ? Or a work around. I've tried using the 'After Update' and 'Before Update Event' to no avail.. Perhaps I'm missing something.

Thx in Advance
0
Comment
Question by:CHYRO
[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
  • 4
  • 2
  • 2
8 Comments
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 9738452
Try setting Cancel to 1 in the AfterUpdate event.
0
 
LVL 11

Assisted Solution

by:Quetzal
Quetzal earned 180 total points
ID: 9738620
AfterUpdate does not have a Cancel option.  Set Cancel to True in the BeforeUpdate event for the field.
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 9738629
Sorry! BeforeUpdate
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

Author Comment

by:CHYRO
ID: 9738806
I tried that, but I keep getting
"You must save the field before you execute the GoToControl action, the GoToControl method, or the SetFocus method"

Here's my code:

Private Sub ctrCell_BeforeUpdate(Cancel As Integer)
Dim strTemp As String
strTemp = RemoveSpace(ctrCell)
If strTemp = "" Then
    Cancel = 1
    ctrCell.SetFocus
Else
    ctrCell = strTemp
End If
End Sub





Public Function RemoveSpace(strVal) As String
strVal = Trim(strVal)
AftSpacePoint = 1
Do While Not InStr(AftSpacePoint, strVal, " ") = 0
    AftSpacePoint = InStr(AftSpacePoint, strVal, " ") + 1
    strVal = Left(strVal, AftSpacePoint - 2) & Right(strVal, Len(strVal) - (AftSpacePoint - 1))
Loop
If Len(strVal) < 12 Then ' If the field contains 2 phones numbers
    If Len(strVal) <> 8 Then ' If the field contains 1 phone number and has the incorrect number of digits
        MsgBox "The phone number has not been entered in the correct format." & vbNewLine & _
        "The standard format is of the form '01 671755'."
        RemoveSpace = ""
        Exit Function
    Else ' Reformat the phone number with a space after the second digit.
        RemoveSpace = Left(strVal, 2) & " " & Right(strVal, 6)
    End If
End If
End Function




... Any ideas ?
0
 
LVL 30

Accepted Solution

by:
nmcdermaid earned 180 total points
ID: 9738842
You don't need the ctrCell.SetFocus. It stays in there anyway.


0
 

Author Comment

by:CHYRO
ID: 9738848
Its actually the line :-
ctrCell = strTemp
That is giving trouble. Is it possible to modify the field in the 'Before Update' Event.
0
 
LVL 11

Expert Comment

by:Quetzal
ID: 9738866
You can't change the value of the field inside BeforeUpdate, just display the message.
0
 
LVL 30

Expert Comment

by:nmcdermaid
ID: 9738886
You might find it handy to add a custom format for that field.

For example if you put this in the format property of the field:

(00) 000000

It will force the data to look like that... it will put zeros in if the user doesn't, making it a bit more obvious to the usre of they have entered something wrong.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

610 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