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

Formatting a control programmatically

Status
Not open for further replies.

mmogul

IS-IT--Management
Dec 1, 2003
218
US
In my code, I read through fields on a form and then based on values in a related query, I update the properties of the control.

This code works when I assign a value to the "width" and format properties. But I get an error ("to set this property, open the form in design view") when I attempt to change the Control type to a combo box. I'm also then attempting to set the Row Source Type and Row Source.

Any suggestions?





Code:
Dim txt As Access.TextBox

  With rs
    If Not .EOF Then
        Do Until .EOF
	Set txt = Me.Controls.Item("txt" & cnt)
	txt.Width = !FieldWidth * 1440
	 If sFieldType = "D" Then  ' this is a date field
                txt.Format = "Short Date"
         Else
         End If 
 
         If sFieldType = "C" Then  ' this is a choice/ combo box field
             txt.ControlType = acComboBox  
    '           txt.RowSource = "tblChoices"
          Else
          End If

etc.

 
The method described in this article uses a custom Visual Basic for Applications function (called from a command button on Form1) to change the ControlType property of a text box (on Form2) to a combo box. You have to use two forms because the ControlType property is available only in a form's Design view. As a result, you cannot use Visual Basic for Applications to change a control's type while the form that contains the control is open in Form view.


Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
Have both a textbox and combo box stacked on top of each other. Hide one and show the other.

You could pop it into design view, make your change, and save, and open in form view. I would advise against that strongly, but it is doable.
 
Thanks for the response. It looks like I need to create the two different controls and hide one.
 
Or two different forms like in the kb article. Get the info from the open form and modify the other one in design view, then open it in form view.

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top