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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unbound and bound a Textbox by VBA code

Status
Not open for further replies.

Goondu

Technical User
Joined
Jan 14, 2004
Messages
92
Location
SG
Hi,

I hope somebody can help me on this.
Can a unbound textbox control source property be change by code?

What i want to do is to assign the control source of the unbound textbox on a form. The form is bound to a table LaborRate and has multiple columns like T1,T2,T3,T4,T5, T6. I need to unbound/bound textbox control source by a checkbox, that means, when i tick the CheckboxT1, the control source is set the column T1 of that table and if i tick CheckT2 the control source is set to T2 of that table and so on.

It is more than just bound/unbound the textbox, it includes deleting the previous input but lets ignore that for the moment.

Thanks
 
Hi,
what you mean ist the RowSource,
Are T1,... in the same SQL (table)?
then just change the boundColumn = column in SQL.
0 means ListIndex

Greets from Germany
Thomas
 
Tom, thank for replying.

No, Rowsource is the properties of the form. I'm refering to the properties of the Textbox on the form. It is the Textbox 'Control Source' which i'm trying to manipulate.

With a single Textbox on a form and by checking the checkbox the Textbox Control Source will change to the correct 'Field Name' of the Table. When uncheck, the Control Source = Null (blank).

Thank You
 
I can think of two ways, one is heavy on vba, the other is a straightforward fudge.

1: On change event of the checkbox, select the active record and set the textbox value equal to the selected field id. (Remember field 1 is record 0). (A neater solution)

2: Make the form with a textbox for each field, select all and set visibility = false
when the checkbox is changed, examine and decide which textbox to make visible. As each is changed then all text boxes should be set to invisible, then make the required one visible.
The textboxes can be laid one over another to save space o n the form.


Merry xmas

Telephoto
 
Thanks for replying Telephoto,

I have tried that straightforward method before. Had to hide 24 Textboxes on that form and the Default View is continuous. It works, i'm looking for another way by just using one Textbox.

Thanks and Merry Christmas from Singapore.
 
Maybe you can do like this.

From code, change the form to design, set the right control source and then change back again.

The control source can only be changed in design mode.

Markus.
 
Private Sub CheckT1_Click()
If CheckT1 = -1 Then
Textbox1.ControlSource = "T1"
else
Textbox1.ControlSource = ""
CheckT1 = 0
CheckT2 = 0
'so on .....to CheckT8
End If

I tried using this, great, now i don't have to create 24 textboxes on a form anymore and make them invisible. I have only 8 checkboxes to code instead of 24 textboxes.
 
good work Larsson!

Just for the record Goondu, because you so "Conveniently" labelled your text boxes, maybe a loop structure can be implemented, ...

For x = 1 To 8

If Me("CheckT" & x).Value = -1 Then
Me("Textbox" & x).ControlSource = "T" & x
Else
Me("Textbox" & x).ControlSource = ""
Me("CheckT" & x).Value = 0
End If

Next x

Hope this helps, good luck either way!
 
Zion7,

Thanks for the looping code.

Merry christmas.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top