?
Solved

SetFocus after Lost Focus

Posted on 2003-11-13
8
Medium Priority
?
511 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Independent Software Vendors: 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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

801 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