Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Time error on SetFocus

Status
Not open for further replies.

e8348

Technical User
Feb 20, 2003
6
US
I have the following code to validate part of a form:

Private Sub Adjuster_Number_BeforeUpdate(Cancel As Integer)

Dim strPt As String
Dim strTi As String

strPt = "Value must be 4 characters long."
strTi = "Incorrect Entry"

If Not Len(Adjuster_Number) = 4 Then
MsgBox strPt, vbCritical, strTi
Me.[Adjuster Number].SetFocus
Cancel = True
Exit Sub
Else
'do nothing
End If

End Sub

I am getting a Run-Time error on this part "Me.[Adjuster Number].SetFocus". It is saying that "You must save the field before you execute to GoToControl Action, the GoToControl method or the SetFocus method."

Any ideas why I might be getting this. I have used it before and did not get any errors.

Thanks!
 
What's the difference between
Adjuster_Number and Adjuster Number?
 
They are supposed to be the same. The name of the field in the form is Adjuster Number. Is that why it is not working? I am referencing two different things.
 
I get it.

OK,
You cannot set focus on an object that has the focus.

Because you are setting your code on before_update you are not moving off that object when the len is < 4 so you are getting and error.

if you take out Me.[Adjuster Number].SetFocus it should work fine.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top