SetFocus not working

spinktec

Registered User.
Local time
Today, 14:20
Joined
Nov 30, 2007
Messages
20
The focus moves to the first tab position on the sub form as soon as I attempt to set enabled property of a contol on the subform to FALSE. I want to disable all controls the subform individually so I've tried moving focus to the parent and seting the entire subform enabled property to false. The focus still moves to the first tab on the subform as soon as i attempt to set the property of any object on the subform.
 
Last edited:
How about posting the various code lines you have tried that do exibit the behavior you described?
 
VehicleSub is the name of the sub form. The code shown here is on the main form. Directly below is the section of code that calls the function.
Code:
Me.ButtonExit.SetFocus
Me.VehicleSub.Visible = False 
Me.VehicleSub.Enabled = False
StatusFieldOn(False)
Me.FieldSN.SetFocus
Me.VehicleSub.Visible = True
Me.VehicleSub.Visible = True

I get an error (can't disable a control while it has focus) when changing the enabled property (below)
Code:
Private Function StatusFieldOn(Activate As Boolean)

Me!VehicleSub.Form.FieldStatus.Locked = Not Activate
Me!VehicleSub.Form.FieldStatus.Enabled = Activate


End Function

As you can see, I move the focus to a control on the parent then I disable the sub, disable certain controls, then enable the sub. But it doesn't work; instead I get an error saying (I can't disable a control that has focus). I don't understand how the sub form control can have the focus when the entire sub form is disabled. I have several controls on the sub form that I disable, but it only throws the error on the control that is at the first tab position of the subform. This makes me think that upon running code that affects the sub form it naturally changes focus from the parent to the sub even if the sub is disabled.
 
I'll check that right now!



Nope, that's not the problem.
 
Is VehicleSub the name of the SubForm *and* the SubFormControl?
 
Yes, it is the name of the form and the control (I see where your're going with this)
 
We must not try and confuse Access too much! :D Go ahead and rename the SubFormControl and see if it make any difference.
 
I still do not quite understand what you are doing but are you aware that setting the focus to a control on a SubForm is a two step process?
Me.SubFormControl.SetFocus
then
Me.SubFormControl.Form.NameOfControlOnSubForm.SetFocus
 
Does it work the same in reverse?
eg. setting the focus from the subform to the parent. That's actually what I'm doing.

I'll try it your way as a two step process.
 
You can move the focus directly to a control on the MainForm from either the MainForm or a SubForm. It is *only* moving the focus to a SubForm that the 2 steps are required.
 
After you got done renaming the SubFormControl, what did this piece of code look like?
Code:
Me.ButtonExit.SetFocus
Me.VehicleSub.Visible = False 
Me.VehicleSub.Enabled = False
StatusFieldOn(False)
Me.FieldSN.SetFocus
Me.VehicleSub.Visible = True
Me.VehicleSub.Visible = True
 
I've moved the setfocus command to the module instead of the code that calls the module. Below is the entire module that changes each control. I'm stumped because I setfocus to the parent control just before I set the sub control to disabled and I still get the setfocus error.

Code:
Private Function StatusFieldOn(Affirmative As Boolean)
Dim SpecialEffectHolder, BackStyleHolder As String

If Affirmative Then

    SpecialEffectHolder = 2
    BackStyleHolder = 1

Else
    
    SpecialEffectHolder = 0
    BackStyleHolder = 0

End If


Me!VehicleSubForm.Form.FieldStatus.Locked = Not Affirmative
Me.FieldSN.SetFocus
Me!VehicleSubForm.Form.FieldStatus.Enabled = Affirmative
Me!VehicleSubForm.Form.FieldStatus.SpecialEffect = SpecialEffectHolder
Me!VehicleSubForm.Form.FieldStatus.BackStyle = BackStyleHolder

End Function
 
We seem to be going around in circles. How about post enough of your db so we can look at it? It would make things a lot easier rather than guessing.
 
That's it right there. It's a piece of code that is called to "turn on" or "turn off" a field depending whether the "affirmative is set to true (turn on) or false (turn off). I'm haveing no problem with any other part except for the "enabled" property. I use a very similar varriation of the same code for every "field" on the form. The code fails in the same place/way each time; at the point where an object that should not have focus is being disabled.

Notice I move focus to the parent (away from the control in all cases) on the line imediately preceding the line that sets the "disabled" property. Why doesn't this work? Is it that in order to manipulate the sub form I insinuate focus to some object on the sub form which makes setting focus to the parent moot?
 
I guess that means you do not want to post a sample. I understand. Oh well.
 
I've stripped everything, even comments, and I can't get the zipped file under 700k.
 
Have you already done Tools>Database Utilities>Compact and Repair Database...?
 
Other options: 1) Create a new db and only import what is needed to demonstrate the problem; 2) Use WinRAR and rename the file as a zip before you upload - letting us know what you have done so we can rename it back. I believe they have trial software or a demo that can be downloaded.
 

Users who are viewing this thread

Back
Top Bottom