SetFocus problem - Run-time Error '2110' (1 Viewer)

_Nickel_

Registered User.
Local time
Today, 09:37
Joined
Nov 11, 2003
Messages
31
All of my forms are subforms on different tabs of my main form.
What I want to do is switch to another tab and open a corresponding record (they are related through a 1:n relationship where the 1-side is the tab I want to switch to).

This is what I tried but it doesn't work:

Private Sub PCname_DblClick(Cancel As Integer)

Dim buffer As String
Dim rst As Recordset

buffer = Form_sfrmWorkstationToPC.PCID.Value
Form_frmMain.frmPC.SetFocus
Me.PCID.SetFocus
DoCmd.FindRecord (buffer)

End Sub

When I run this code I get the following error message:
Run-time Error '2110'
Microsoft Access cannot move the focus to the control PCID

I am using the same code on other tabs of my main form and it works there but only if the focus is already on the ID field in the form that I want to switch to. If it's not Access just switchs tabs without going to the record that I want it to go to (but I get no error message :confused:

Please tell me what I am doing wrong!
Thanks :)
 

SQL_Hell

SQL Server DBA
Local time
Today, 09:37
Joined
Dec 4, 2003
Messages
1,360
Hi,

when you do this:

Form_frmMain.frmPC.SetFocus

are you on a new record?

If so it is probably not letting you change focus because it is expecting you to add a value to a required field.
 

_Nickel_

Registered User.
Local time
Today, 09:37
Joined
Nov 11, 2003
Messages
31
SQL_Hell said:
Hi,

when you do this:

Form_frmMain.frmPC.SetFocus

are you on a new record?

If so it is probably not letting you change focus because it is expecting you to add a value to a required field.

Thanks for the reply :)

No, I am not on a new record. It goes to the record I was looking at when I last looked at that form (which is an already existing record with all the required fields entered).
 

SQL_Hell

SQL Server DBA
Local time
Today, 09:37
Joined
Dec 4, 2003
Messages
1,360
Hi,

what kind of control is PCID?
 

_Nickel_

Registered User.
Local time
Today, 09:37
Joined
Nov 11, 2003
Messages
31
PCID (PC ID) is an AutoNumber field.

Rich said:
Try setting focus to the correct page first

By using something like this:

Forms(0).RegisterStr0.Value = 3 ?

I tried this as well but it still gives me the same Run-time error. The problem is setting focus to the PCID field. I have no problem to get the focus to the right tab.
 

_Nickel_

Registered User.
Local time
Today, 09:37
Joined
Nov 11, 2003
Messages
31
I just tried the following but it gives me the run-time error as well:

Form_frmMain.Seite10.SetFocus
Me.PCID.SetFocus


I also tried using PCName instead of PCID (they are both unique on the same table/forms) and then it works if the focus in the tab that I want to switch to is already on PCName (but not if it isn't). :confused:
 
Last edited:
R

Rich

Guest
You can only use Me. on the subform that the code is on, since you're switching to another subform I suspect you'll have to use the full forms reference
 

_Nickel_

Registered User.
Local time
Today, 09:37
Joined
Nov 11, 2003
Messages
31
Thanks Rich!
I found out what caused the runtime error: I thought that Me was referring to the form that currently had the focus and not the form that the code is on :rolleyes:
Me.PCID.SetFocus was trying to set a focus to a field in the subform that was hidden :rolleyes:

Now I only need to work out how to set focus to the PCID field in the PC form. I can get as far as setting focus to the right tab by using this:
Form_frmMain.Page10.SetFocus
but now I need to set the focus to the PCID field in form "frmPC" which is a subform on this tab. I already tried Rich's suggestion of "SomeField.SetFocus" but it won't work. I also tried "SomeForm!SomeField.SetFocus" but that doesn't work either.
Can anyone tell me how to do this?

Thanks
 
R

Rich

Guest
You have to use the full forms references, the easiest way to get them is to use the CodeBuilder whilst in design view
 

Users who are viewing this thread

Top Bottom