Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SubForm

Status
Not open for further replies.

JDU

Technical User
Dec 23, 2002
182
US
I have a subform that's bound to a table. There is a field in this table whose name changes based on the day of the week. For example the table fields may be ID, Name, Sunday once and at other times it might be ID, Name, Monday. I dynamically create this table via code.

This is the problem. Since one particular field in this table changes, when the form with the subform opens, it asks to input a parameter for that field, since now it has a different name.

IS THERE ANY WAY TO CHANGE THE NAME AND CONTROL SOURCE OF THAT FIELD IN THE SUBFORM VIA CODE AND IF SO HOW, ALSO WILL THIS SOLVE THE PROBLEM?

Thanks
 
On your subform's Control Source property, set it to blank (""). Now, on your main form's On_Open() event, set Me.mySubFormControlName.Form.mySubFormsDayOfWeekControlName.ControlSource = "Monday"
replacing the identifier names and "Monday" with whatever day it should be (i.e. DayOfWeek(Date())).

YOU ARE WELCOME NO PROBLEM ANY TIME





EVERYTHING IS FUNNIER IN ALLCAPS
 
Foolio12,your solution worked, Thankyou. This is the problem I have now. I named the control on the subform txtDay. Therefore in Form View the field heading on the subform is txtDay and not Monday etc.

I tried this code but got the error that this only works in Design view.

Me.subfrmPeopleOnCALOrOffForSpecificDay.Form.txtDay.Name = strPeopleOnCALOrOffForSpecificDayDayDate

Help Please and Thanks.
 
I spoke too soon, this is not fixed. This is what I have on the form's open property.

Me.subfrmPeopleOnCALOrOffForSpecificDay.Form.txtDay.ControlSource = strPeopleOnCALOrOffForSpecificDayDayDate '(This is a string variable that holds the field name)

However this does not work. It still gives me the parameter input box and when I input something I get #Name? as the result.

Please Help and Thanks.
 
It seems that the ControlSource is getting set; however, is not being reflected on the form. I tried requery and refresh.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top