Solved

SetFocus after Lost Focus

Posted on 2003-11-13
8
509 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 45 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

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 45 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
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…
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…

691 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