Setting Text and combo boxes to not visible in a subform.

pturco

New member
Local time
Today, 18:15
Joined
Sep 22, 2008
Messages
8
I have text and combo boxes on a subform which I would like when loaded to not appear on the form. They are automatically updated from other boxes on the main form. I tried setting their property to Visible=No and this did not work. Then I tried the following code in the main form load event procedure:

Private Sub Form_Load()
[Form_A Crew Subform].Shift_Date.Visible = False
[Form_A Crew Subform].Shift.Visible = False
[Form_A Crew Subform].Supervisor.Visible = False
[Form_A Crew Subform].Employee_Name.Visible = False
End Sub

Now when I open the main form I am getting:

Run-time error '2165':
You can't hide a control that has the focus.

Any help or suggestions appreciated,
Pam
 
I tried setting their property to Visible=No and this did not work.
What do you mean by this? What happened when you tried to set the property to no manually? If you can't set the property manuall then you are unlikely to be able to do it in code.

Just curious but why are you doing this?

Chris
 
You cannot hide controls in Datasheet view forms, which is the view most subforms are displayed in. If your purpose in making them invisible is to only allow them to be populated thru code from the main form, simply set the Locked property to Yes.
 
First, I went to the property for each of the boxes and changed the visible property to No. I thought this would make the box not visible when the form was opened, but it didn't seem to change anything.

As for why I am doing this. I may be going about this incorrectly but it was what I came up with. I have a main form which has 4 subforms on it in tab format. I would like the user to be able to enter the "Date", "Shift" and "Supervisor" on the top of the main form. The reason is that for the entry's enter for the day (it is data of jobs done by employees on a shift) this info will not change. Then the user will choose the employee from a combo box located on each tab which queries the employees for each crew. Then in the subform they will enter the jobs completed by that employee on that shift. Choose the next employee and repeat.

This way the user does not have to re-enter the date, shift and supervisor for each record. So I have these set these up on the main form as Unbound controls, then have the boxes in the subform reference them to fill in when the user enters them. This is working, I just don't want these fields to show up in the subform so that the data is not displayed twice.
 
Private Sub Form_Load()
[Form_A Crew Subform].Shift_Date.Visible = False
[Form_A Crew Subform].Shift.Visible = False
[Form_A Crew Subform].Supervisor.Visible = False
[Form_A Crew Subform].Employee_Name.Visible = False
End Sub

you are trying to set the status of certain controls, when you open a form, which is certainly a legitimate thing to do
BUT ... the thing your error message meant was that when you open a form, the first field it goes to is the first one in the tab order. now i assume that field is one of the above, and you cant hide the field that is currently active, as access gets confused!

note in passing that if you set the fields

.enabled property to false AND
.locked property to false

you get the "greyed" effect, which may be better for you
 
I had a similar situation and got around this by not displaying the fields you wanted invisible to begin with. My form also allowed me to populate them through statements such as:
Forms!Mainformname!SubformName.Form!FieldName = Forms!Mainformname!SubformName.Form!FieldName
There is a copy of my example here: Note look at frmAddCompetencies and the code for SubfrmAddCompetencies
http://www.access-programmers.co.uk/forums/showthread.php?t=161505http://www.access-programmers.co.uk/forums/showthread.php?t=161505
cheers
Tanya
 

Users who are viewing this thread

Back
Top Bottom