SetFocus and go to new record

amerifax

Registered User.
Local time
Today, 01:44
Joined
Apr 9, 2007
Messages
304
I am using Access 2010 with XP Pro.

I am using the following code in my form:

Code:
Private Sub Seal_Change()
    
    If Len(Seal.Text) = 6 Then SC.SetFocus
    
End Sub

It works great. I tried to use the same code for my next Control (SC),

Code:
Private Sub SC_Change()

    If Len(SC.Text) = 6 Then Seal.SetFocus

End Sub

But it does not work, I get the following error:

Run-Time error '2110':
Microsoft Access can't move the focus to the control Seal

The code I am trying to use with the control is not exactly what I need in the end, so in the process of fixing it, I was hoping someone could help me with the additional (proper) code I need. This is what I am doing, which may make it a little easier to understand. I have a Control for Seal and SC. After the 6 characters for the seal number have been entered I want the cursor to move to the next control for SC (which it does). Then after I enter the 5 characters for SC I would like to know how to change the code so that it will move to the Seal Control in the next record, which I would like to be a new record. So basically after I have entered the SC number I would like to move down to a new record and have the cursor waiting in the Seal Control. The once special characteristic of the SC Control is I am using an input mask which does the following "__-___". It is putting a "-" in the 3rd position, which is being saved with the data.

I hope I have explained myself well enough and thanks in advance for any help.

Heather
 
So change the second part to this:
Code:
Private Sub SC_Change()
 
    If Len(SC.Text) = 6 Then 
       Me.Dirty = False
    End If
 
End Sub

And then in the Form's After Update event put:
Code:
If Not Me.NewRecord Then
   DoCmd.RunCommand acCmdRecordsAddNew
   Me.Seal_Change.SetFocus
End If
 
Last edited:

Users who are viewing this thread

Back
Top Bottom