Make Combo Box in SubForm read only On Open?

David Ball

Registered User.
Local time
Today, 18:45
Joined
Aug 9, 2010
Messages
230
Hi,
I have a form containing a subform. The subform has a combo box (FIC Number) that the user can select values from. I want the combo box to be read only until the user presses an “Edit Profiles” button. The user can scroll through the main form and view "Profiles" that have been previously set up but can not change any Profiles until they press the "Edit Profiles" button.
I have tried using an “On Open” event procedure for the Form as below:
Private Sub Form_Open(Cancel As Integer)
Forms![formEquipmentType]![subformTestEquip/FIC Subform]![FIC Number].Enabled = False
End Sub
Initially I got an error message "You can not disable a control while it has the focus".

I tried setting the Focus onto the cmdClose button first (as per below) but still get the same message.
Private Sub Form_Open(Cancel As Integer)
cmdClose.SetFocus
Forms![formEquipmentType]![subformTestEquip/FIC Subform]![FIC Number].Enabled = False
End Sub

Is there a way to disable the combo box in the subform so that it is read-only on opening the form, until the “Edit Profiles” button is selected?

I think I am OK on setting up the "Edit Profiles" button and associated code, I just need help with disabling the combo box when the form opens.
Thanks very much.
Dave B
 
Why not set the enabled property in design view and save the form that way, so it opens disabled without code?
 
Thanks. Believe it or not I didn't even know I could do that!

Dave B
 
No problem Dave, happy to help.
 
Actually, I just noticed I still get the same problem later on.

After enabling the combo box with the "Edit Profiles" button and making some changes I would like to make it read only again with a "Disable Edit" button.

When I try this I get the same problem with the message "Can not disable a control that has the focus". Even if I click the Save button first before clicking the "Disable Edit" button I get this message.

I'm not sure why this combo box retains the focus?

Dave B
 
Is this from the main form with the combo on the subform or something? I'd consider putting some other control first in the subform tab order, or setting focus to some other control on the subform first.
 
Thats it! I set the Focus to another control in the subform as you suggested. I had made the mistake of setting the focus to a control on the form.

Thanks very much. :)

Dave B
 
Excellent, glad it worked for you.
 

Users who are viewing this thread

Back
Top Bottom