Solved

SetFocus after Lost Focus

Posted on 2003-11-13
8
507 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
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

828 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