Link to home
Start Free TrialLog in
Avatar of Skip Sleeper
Skip Sleeper

asked on

Change control source of text box

Hi Experts,
In Access 2010, I am trying to write additional VBA code within a command button click event that opens another form, that will change the control source of a text box in the new form.   And I'm not sure if the code should go in the click event or on the load or open events of the new form.  Any help is greatly appreciated!  Sample of problem in attached database.  Thank you!Database_e.g.ChangeTextBoxControlS.accdb
Avatar of Daniel Pineault
Daniel Pineault

Since your Form2 is unbound, I'm not following changing textbox's control source.  What's the purpose of this exact? Could you give us a concrete usage example?

As for the direct question, the code would normally be in the form itself.  You could possibly pass an OpenArgs value when making the call to open the form and then in the form itself process it to adjust the control source appropriately.
Avatar of Skip Sleeper

ASKER

Hi Daniel,

In the db I'm working on, form 1 is a dept. specific form with options to launch various forms of a physical inventory.  I'm trying to reduce the amount of forms by having a master form that changes it's recordsource to show just the calling department's items (this I've done successfully).  On the master items form, I'm trying to just change a textbox title in the header to indicate that they are working on their department's items.  Seems simple but I just can't seem to get it.  Thanks!
I'm trying to just change a textbox title in the header

Is the form a Datasheet?  If so, the "title" of a "header" (name of the column at the top) can be set using two methods:
1.  The caption of the control's "attached" label ("attached" is important here - unattached labels will NOT act as header labels).
2.  The "Datasheet Caption" property of the control itself.

You should be aware that if you create a datasheet using a wizard and it creates more than 1 column of controls in design view, the label for controls in columns 2 and later are NOT attached to their controls.  You can tell if a label is attached by selecting the control and seeing if its label has a big grey box on the top-left corner (unattached labels do not have one).  Also, attached labels move with the control - unattached labels do not. If not attached, you will need to attach them by cutting the label to the clipboard, selecting the control, and pasting the label to the control - now it is attached.  Note:  you will want to remove the Layout on your datasheet form using the Arrange ribbon.

Labels are better because you can see what the headings are at a glance in design view.  You have to select the control and look at the Datasheet Caption property on the property window to see what the value of the datasheet caption is.
o.k. I just took a look at the sample db and form2 is a single form, not a datasheet, so "I'm trying to just change a textbox title in the header" does not make any sense.  

Either we're talking about a form that SHOULD be a datasheet, or we are talking about the Control Source property of a textbox control and the Caption property of its label on a single form.

What up?
p.s.  Just because you can easily switch a single or continuous form to a datasheet, datasheets have additional properties, methods and behaviors, as well as a different way to display the controls.

...but you all know that, right?.....
p.s.s  I guessed that form2 should be a datasheet because when you select the textbox, you can see the dashed outline of a Layout around the control and label - only a form created by the datasheet wizard does that....
Hi Mark,

Attached please see the db I'm working on.  From frm_switchboard, choose Dietary then Manage Items.  The form that is called is ItemsMaster.  It is a single form with a text box in the header identifying to the user that they are working with Dietary's items.  The control source is currently static.  I hope to use this same form but add code so its recordsource is set to the department calling the form to cut down on the number of forms to manage (I have managed to do this).  I just want a simple way to change the the text box contents so the end user knows it's their items.  I apologize for sending the sample db, I thought it would be a simple way of showing what I'm trying to do.

Thanks!
VernonHomes_Inventory_ver-1.0-not-.accdb
ASKER CERTIFIED SOLUTION
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Gustav,

I never thought to try it with another form.  Thanks for the insight!