SET FOCUS ERR.2165

D

Dave180

MSA 2003

SETFOCUS - Fails 2165
-------------------------

Forms!frmmaster = the form
forms!frmmaster!mysubform = a subform on the master form
"ctlControlObject.Name = strBUT" equates to a reference of the 'control
array' in the subform

The subform has 100 controls - The Master form has a Restart and Close
control and some labels

I use the following code segment called when the Master form is opened and
also when the RESTART Control is clicked on the Master Form.
In both instances the calling code has been told to loop to this segment (if
conditions are correct) 10 times

-------- Code Segment begin
---------------------------------------------------------

Case Is = "frmINITHideSquares" ' HIDE THE BORDER SQUARES
'' MAKES CMDBUT INVISIBLE

If ctlControlObject.Name = strBUT Then
Forms!frmmaster.CMDClose.SetFocus ' Move focus away from
CMD ' can't hide it else
With ctlControlObject
.Tag = "B"
' On Error Resume Next ' SOMETIMES!?! The
Control still has the focus (despite .setfocus)
' Forms!frmmaster!CMDClose.SetFocus ' Move focus away
from CMD ' can't hide it else
' On Error GoTo errtrap ' SOMETIMES!?! The
Control still has the focus (despite .setfocus)
.Visible = 0 <<<<<<< HERE 2165 ERR
End With
End If

-------- Code Segment end
--------------------------------------------------------------

Occassionally! I get a 2165 error in the line trying to hide a control on
the subform despite having forced the focus away to a control on the 'master'
form.

As you can see from the commented out lines in the loop - I've tried a few
solutions to trap this. - I failed!
Is this a hardware thing? - I'm running my APP on a fast PC
Could the PC be running faster than MSA can move the focus away from the
Control I'm trying to hide?

The 2165 error appears NOT to occur on 'Form Load' - but only (and then
sometimes only) when the RESTART routine is executed.
(As stated - both 'Form Load' and 'Restart' events use the same code.

Any advice as to how to prevent this err occuring will be gratefully
appreciated.

Regards,
Dave

(I'm not Dumb - It's just the way I walk!)
 
D

Dale Fye

Dave,

I generally have an unbound control on my forms titled "txt_Dummy".

I set the background and border styles of this control to transparent, and
the width of the control to 0. You can put it anywhere on the form that is
visible, but all you will see is a very small line (you can actually set the
height to zero too, but if you do this, you will never find it again).

Then, in my code that hides controls, I include an error handler that checks
for Err.Number = 2165. If that error comes up, I set the focus to txt_Dummy,
and follow that up with a Resume command.

--
HTH
Dale

email address is invalid
Please reply to newsgroup only.
 
D

Dave180

Thanks Dale
Sounds like good advice - I'll give that I try.
I've resolved my own problem by recalling the whole routine on 2165 until
the err doesn't occur - which is good enough for me - but obviously not a
solution in all cases!
I'll see if your solution manages this 'sometimes-problem' more elegantly.

Dave.

(If a nutcracker would solve the problem - I'd use a sledgehammer!)
 
D

Dave180

F-Up
No that didn't work either unfortunately (I wondered if it would 'cos I'd
already changed the focus between the Close and Restart Buttons when this
error occurs.)

Trying your suggestion - I either got a permanent loop or - if I used the
code - (called by "on error goto errtrap") the error trap fails 2165 !!!
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
errtrap: '' Deal with occassional ERR with
moving focus (Hiding Squares)
If Err.Number = 2165 Then
Forms!frmmaster!txt_Dummy.SetFocus
ctlControlObject.Visible = 0 <<< App loops if omitted with RESUME
- Fails 2165 as is !!!

Err.Clear <<< Tried with and without
Resume Next <<< Resume NEXT used since handler
now does next line anyway
Else
Debug.Print Err.Number
Stop
End If

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

I'll resort to sledgehammers for this App I think - but I'd rather
understand why 2165 ever occurs here.

Could MSA fail here because focus is moving from subform to the master form?

Thanks again, anyway.
Dave.
 
D

Dale Fye

Sorry,

Since you are looping through all of the controls on the form, you need to
add a line in to test if the control name is "txt_Dummy", and if so, don't
try to hide or disable it.

HTH

Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top