Microsoft Knowledge Base Email Alertz

KBAlertz.com: Moderate: Requires basic macro, coding, and interoperability skills.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 135381 - Last Review: January 19, 2007 - Revision: 3.3

ACC: How to Programmatically Change a Control Type

This article was previously published under Q135381
Moderate: Requires basic macro, coding, and interoperability skills.

SUMMARY

This article shows you how to programmatically change a control on a form from one type to another. By using the ControlType property in a Visual Basic for Applications procedure, you can change a text box into a combo box, a toggle button into an option button, and so on.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

MORE INFORMATION

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.

To programmatically change a form's control type, follow these steps:

  1. Open the sample database Northwind.mdb.
  2. Create a new form not based on any table or query and name it Form1.
  3. Add a command button to the Form1 form and set its properties as follows:
    Name: Command0
    Caption: Change Control Type
  4. Set the command button's OnClick property to the following event procedure:
          Private Sub Command0_Click()
    
             If Forms!Form2.CurrentView <> 0 Then DoCmd.OpenForm "Form2", _
             acDesign
    
             If Forms!Form2![CategoryName].ControlType = acComboBox Then
               Forms!Form2![CategoryName].ControlType = acTextBox
             Else
               Forms!Form2![CategoryName].ControlType = acComboBox
             End If
    
          End Sub
    						
  5. Close and save the Form1 form.
  6. Make a copy of the Categories form and call it Form2.
  7. Open the Form2 form in Form view.
  8. Open the Form1 form in Form view and click the command button. Note that the Form2 form opens in Design view and that the CategoryName control changes from a text box to a combo box. When you click the Change Control Type button again on the Form1 form, the CategoryName control in the Form2 form changes back to a text box.
NOTE: When you change a control to another type of control, Microsoft Access copies the appropriate property settings from the original control to the new control. If a property exists for the original control but not for the new control, Microsoft Access does not copy it. If a property exists for the new control but not for the original control, Microsoft Access sets the property to the default control for that type of control.

REFERENCES

For more information about the ControlType property, search the Help Index for ControlType.

APPLIES TO
  • Microsoft Access 95 Standard Edition
  • Microsoft Access 97 Standard Edition
Keywords: 
kbhowto kbprogramming KB135381
Retired KB ArticleRetired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please