Problem with run-time error 2110 on a form, 'can't move focus to control 2'

KeahiG

New member
Local time
Today, 06:19
Joined
Feb 24, 2013
Messages
5
Hi There! I'm fairly new to access and very new to vba, so this may be an easy fix or maybe I am doing it totally wrong. Either way, I thank anyone who helps in advance :)

I am using Access 2007 and have a form in which the user will input text for a contract on 20 separate fields. I wanted the user to be able to type in a field and have the program setfocus to the next field to continue. This is the code that I currently have:

Private Sub Ctl1_Change()
If Len(Me.Ctl1.Text) = 130 Then Ctl2.SetFocus
End Sub

Once I reach the end of the field (at 130), the error box pops up. However, I noticed that if I just continued typing with out stopping, the error box will pop up and close and the cursor will setfocus to the next field.

Could someone help me? I don't know what is going on and after doing some research, I am stuck.

Thanks again :)
Keahi
 
I have notice there is no end if .hope that solves it ?

regards
 
Hi ypma,

Thanks for your reply! I tried adding in the End if in hopes that it was just that simple change, however the error is still popping up. It's really weird how it just flashes (pops up but then goes away) if you just ignore it and continue typing - it will go to the next line like I wanted it to. Here's the revised code I have:

Private Sub Ctl1_Change()
If Len(Me.Ctl1.Text) = 130 Then
Ctl2.SetFocus
End If
End Sub

Any suggestions? I am a newbie, so I have no ideas. Thanks!
 
Hi ypma,

Disregard my previous post! :) It is working now. I just saved all changes, exited the program and when I went back in, I was working how I wanted it to. I'm glad it was a simple fix.

Thanks for your help!
 
Hi There!

I hope someone can help me with this. I tried to add the End If and it seemed to work, but when I went back into the program, the error message popped up again 'error 2110, can't move the focus to the control 2'.

Here is what I have:

Private Sub Ctl1_Change()
If Len(Me.Ctl1.Text) = 130 Then
Ctl2.SetFocus
End If
End Sub

Private Sub Ctl2_Change()
If Len(Me.Ctl2.Text) = 130 Then
Ctl3.SetFocus
End If
End Sub

Private Sub Ctl3_Change()
If Len(Me.Ctl3.Text) = 130 Then
Ctl4.SetFocus
End If
End Sub

Private Sub Ctl4_Change()
If Len(Me.Ctl4.Text) = 130 Then
Ctl5.SetFocus
End If
End Sub

Basically, I want the user to be able to enter in information on lines in a contract and not have to tab to the next field if the sentence runs longer than the control 1 will allow. Right now, the error message will pop up but if I continue to type, it will go away and setfocus to the next control - what I want it to do (but without the error msg pop up).

I feel like I am missing something. Or is there another way I can achieve that?

Thank you ahead of time :)
 

Users who are viewing this thread

Back
Top Bottom