473,394 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how do i refer to a button using a string

Ok, I have a form with about 750 buttons and i want to be able to refer to a button based on a string.

For example, instead of writing...

Button1_A.BackColor = Color.ForestGreen

I want to write...

Dim Q_No As String
Dim Btn_Type As String
Dim Btn As String

Private Sub Another_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Another_Button.Click
Q_No = "1"
Btn_Type = "A"
Btn = "Button" & Q_No & "_" & Btn_Type
Btn.BackColor = Color.ForestGreen()
End Sub

But i just get the error message "'BackColor' is not a member of 'String'"
Sep 23 '10 #1
3 1557
MikeTheBike
639 Expert 512MB
Hi

Is this Access 2007 or later as I dont recognise the Click argument (look like .Net arguments)?

But if it is Access and it is compatable with earlier versions then something like this should work

Expand|Select|Wrap|Line Numbers
  1. Btn = "Button" & Q_No & "_" & Btn_Type
  2. Me.Controls(Btn).BackColor = Color.ForestGreen()
???


MTB
Sep 23 '10 #2
No its Visual Basic 2008,

Dont worry though i found the answer to be
Expand|Select|Wrap|Line Numbers
  1.  
  2.         Dim Q_No As String
  3.         Dim Btn_Type As String
  4.         Dim BtnName As String
  5.  
  6.         Dim Btn As Button
  7.  
  8.         Q_No = "1"
  9.         Btn_Type = "A"
  10.         BtnName = "Button" & Q_No & "_" & Btn_Type
  11.  
  12.         Btn = TryCast(Me.Controls.Find(BtnName, True)(0), Button)
  13.  
  14.         If Not Btn Is Nothing Then
  15.             Btn.BackColor = Color.ForestGreen
  16.         End If
But thank you for your reply
Sep 24 '10 #3
MikeTheBike
639 Expert 512MB
Hi again

Just been looking ad VB Express 2008 (which as far as I can see is .Net by any other name), and find that the code in my last post does seem to work in .Net and a little easier to follow (in my opinion, but depend what you are used to), ie.
Expand|Select|Wrap|Line Numbers
  1. BtnName = "Button" & Q_No & "_" & Btn_Type 
  2. Me.Controls(BtnName).BackColor = Color.ForestGreen
This of course my not be the prefered way of doings thing in .Net !!??


MTB
Sep 27 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Raghuram Banda | last post by:
Hi, Can any one help me, how to create a Radio button using DOM with default one option is selected Thanks in advance
7
by: | last post by:
Hello, I would like to do the following from a asp.net button click: <form method="POST" action="https://www.1234.com/trans_center/gateway/direct.cgi"> <input type="hidden" name="Merchant"...
7
by: support | last post by:
Hi, I am trying to change the text of a Command button using the Windows API Function SetWindowText, which I have declared as follows: <DllImport("User32")_ Public Function...
3
by: Jonay Aloat | last post by:
I need to implement the following. Shoul I use multimap or write a string hash class? ie Brand Product ========================== Samson ...
1
by: singh79 | last post by:
Hi Pls Help Me. I Am using Ten Check Box , i want to save check Box Checked values in Save button .,Using web Application Asp.net2.0 With C#. Regards atul Singh
2
by: letmetry | last post by:
Hi all, Is there any way to click on link or button using c++..
1
by: vimala5 | last post by:
code for closing a window using ALT f4 or pressing cross button using javascript
14
by: squrel | last post by:
Hello everyone, I m using some button using toolbar such as Add,Save,View,.... my save button is not working.... it doesnt give me any error but does not save to my database.... or showing in my...
2
by: bhanuk | last post by:
how to get data from a textfile by clicking the button using vb6.0
3
paulrajj
by: paulrajj | last post by:
hi to all, How to Enable a text field only on selecting a radio button using only getElementById..
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.