locked
array of textbox(ms access)

    Question

  • hi everyone

    ı have a form in access. in form, there are 9 textboxes. in vba, ı want to assign taxtboxes' name to an array. and I created a loop and condition. If this condition id true, color of textbox array element refers will be change. but ı can not handle it .

    please help,

    thank you... 

    Sunday, May 08, 2011 2:18 PM

Answers

  • Hi Queen_tur61,

    Based on your description, it is vague to fully understand. What do you mean of "a form in access", is it the Microsoft Access which is a database software? And as you mentioned, "in vba", I am not sure whether your application is a Visual Basic application? If so, I think you post your question in a wrong froum as this is a C# forum. For VB question, you can post it in the VB froum:http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/threads

    If I misunderstand your description. I presume that you use the C# language. Then I am not sure which color of TextBox control do you want to change, you can set the ForeColor property to set the TextBox's text color and set the BackColor property to set the background color. Here is a sample about changing the Forecolor property:

    foreach (Control c in this.Controls)
       {
        if (c is TextBox)
        {
         TextBox t = c as TextBox;
    
         switch (t.Name)
         {
          case "textBox1": t.ForeColor = Color.Red; break;
          case "textBox2": t.ForeColor = Color.Blue; break;
           ......
          case "textBox9":t.ForeColor=Color.Brown;break;
          default: break;
         }
        }
       }

    I add 9 TextBox controls into form deirectly. It means the TextBox's container is form, not other control like GroupBox or Panel and so on. If the TextBox's container is GroupBox, then you should change "Control c in this.Controls" to "Control c in groupBox1.Controls".

    If any misunderstanding, please feel free let me know. Thanks.


    Vin Jin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Aspen VJ Tuesday, May 17, 2011 1:16 AM
    Wednesday, May 11, 2011 2:54 AM

All replies

  • Not fully understand, please clarify it in detail.


    Please Mark it as answer, if it helps solve your problem.
    Wednesday, May 11, 2011 2:16 AM
  • Hi Queen_tur61,

    Based on your description, it is vague to fully understand. What do you mean of "a form in access", is it the Microsoft Access which is a database software? And as you mentioned, "in vba", I am not sure whether your application is a Visual Basic application? If so, I think you post your question in a wrong froum as this is a C# forum. For VB question, you can post it in the VB froum:http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/threads

    If I misunderstand your description. I presume that you use the C# language. Then I am not sure which color of TextBox control do you want to change, you can set the ForeColor property to set the TextBox's text color and set the BackColor property to set the background color. Here is a sample about changing the Forecolor property:

    foreach (Control c in this.Controls)
       {
        if (c is TextBox)
        {
         TextBox t = c as TextBox;
    
         switch (t.Name)
         {
          case "textBox1": t.ForeColor = Color.Red; break;
          case "textBox2": t.ForeColor = Color.Blue; break;
           ......
          case "textBox9":t.ForeColor=Color.Brown;break;
          default: break;
         }
        }
       }

    I add 9 TextBox controls into form deirectly. It means the TextBox's container is form, not other control like GroupBox or Panel and so on. If the TextBox's container is GroupBox, then you should change "Control c in this.Controls" to "Control c in groupBox1.Controls".

    If any misunderstanding, please feel free let me know. Thanks.


    Vin Jin [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Aspen VJ Tuesday, May 17, 2011 1:16 AM
    Wednesday, May 11, 2011 2:54 AM