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

changing control source at runtime

Status
Not open for further replies.

neerajam

Technical User
Mar 4, 2002
23
US
I have a combobox with different scenarios. For example, the combo box consists of different quality problems encountered with a raw material. I have three text boxes. Depending on the problem with the raw material, I would like the textboxes to be attached to different control sources present within a query. Can I do it this way or can each text box be attached to one control source only.
Thanks for the answer in advance.
 
Sure, this can be done. Include code similar to the following in the After Update event of the combo box.

Select Case cbobox.Value
Case "..."
txtbox1.ControlSource = "..."
txtbox2.ControlSource = "..."
txtbox3.ControlSource = "..."
Case "..."
txtbox1.ControlSource = "..."
txtbox2.ControlSource = "..."
txtbox3.ControlSource = "..."
Case "..."
txtbox1.ControlSource = "..."
txtbox2.ControlSource = "..."
txtbox3.ControlSource = "..."
Case etc....
End Select dz
dzaccess@yahoo.com
 
Private Sub subject_AfterUpdate()
(subject is the combobox name)
Select Case subject.Value

Case "VA Content out of spec"
Text1.ControlSource = VAContent
Text2.ControlSource = MaxVAContent
text3.ControlSource = MinVAContent
Label3.Caption = "VA Content"
Label5.Caption = "Max VA COntent"
Label6.Caption = "Min VA COntent"
Thanks very much for your help. I tried out the suggestion and got the following error message.


Case "Melt Index out of spec"
Text1.ControlSource = CertifiedMeltIndex
Text2.ControlSource = MaxMeltIndex
text3.ControlSource = MinMeltIndex
Label3.Caption = "Certified Melt Index"
Label5.Caption = "Max Melt Index"
Label6.Caption = "Min Melt Index"
End Select
End Sub

When I run this code, the labels run fine. However I get a 0 for the controlsource value and #Name? in the text box on the form. What am I doing wrong.
 
Hi!

For Access to recognize a field as the control source of a textbox, the field must be part of the recordsource of the form. If it isn't, you get the error you are experiencing.

hth
Jeff Bridgham
bridgham@purdue.edu
 
Hello neerajam:

Jeff is right. If you specify a field name in the Control Source Property, the field must be in the Recordset of the form. The Control Source Property can also be set to an expression, in which case, the text box would be unbound. Are VAContent, MaxVAContent, and MinVAContent field names? They have to be enclosed in quotes.

Text1.ControlSource = "VAContent"

dz
dzaccess@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top