473,385 Members | 1,958 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,385 software developers and data experts.

Refer to a control through a function

157 100+
Expand|Select|Wrap|Line Numbers
  1.  
  2. Function Ctrl_msgbox(control as string)
  3.  
  4. msgbox [form_1].control
  5.  
  6. end function
  7.  
  8.  
  9. sub test
  10. call ctrl_msgbox(tbx_information)¨
  11. end sub
  12.  
Is this possible?
Jan 30 '09 #1
4 1406
DonRayner
489 Expert 256MB
A function would be used something like this.

Expand|Select|Wrap|Line Numbers
  1. Public Function Ctrl_msgbox(control As String)
  2.     Ctrl_msgbox = Forms!form_1!(control)
  3. End Function
  4.  
  5. Sub test()
  6.     Me.MyControl = Ctrl_msgbox(tbx_information.Name)
  7. End Sub
  8.  
And a sub would be used something like this. (This is probally what you're after)

Expand|Select|Wrap|Line Numbers
  1. Public Sub Ctrl_msgbox(control As String)
  2.     msgbox Forms!form_1!(control)
  3. End Function
  4.  
  5. Sub test()
  6.     Call Ctrl_msgbox(tbx_information.Name)
  7. End Sub
  8.  
Jan 30 '09 #2
FishVal
2,653 Expert 2GB
Or it could be something more straightforward.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function Ctrl_msgbox(ctrl As Object)
  3.     Msgbox ctrl.Value
  4. End Function
  5.  
  6.  
  7. Sub Test
  8.     Call ctrl_msgbox(Me.tbx_information) 'I guess the sub is in form module
  9. End Sub 
  10.  
Jan 30 '09 #3
MrDeej
157 100+
Thats how simple it is :=)
Thank you
Jan 30 '09 #4
ADezii
8,834 Expert 8TB
@MrDeej
You can also pass a specific Control to a Function, query its Type, then take appropriate action as follows:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function fQueryControl(ctlControl As Control)
  3.   Select Case ctlControl.ControlType
  4.     Case acCommandButton
  5.       Debug.Print ctlControl.Name & " is a Command Button"
  6.     Case acTextBox
  7.       Debug.Print ctlControl.Name & " is a Text Box"
  8.     Case acComboBox
  9.       Debug.Print ctlControl.Name & " is a Combo Box"
  10.     Case acCheckBox
  11.       Debug.Print ctlControl.Name & " is a Check Box"
  12.     Case acImage
  13.       Debug.Print ctlControl.Name & " is an Image Control"
  14.     Case acLabel
  15.       Debug.Print ctlControl.Name & " is a Image Control"
  16.     Case acListBox
  17.       Debug.Print ctlControl.Name & " is a List Box"
  18.     Case Else
  19.       Debug.Print "Don't really care!"
  20.   End Select
  21.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim ctl As Control
  3. For Each ctl In Me.Controls
  4.   Call fQueryControl(ctl)
  5. Next
  6.  
OUTPUT:
Expand|Select|Wrap|Line Numbers
  1.  
  2. Command7 is a Command Button
  3. Command8 is a Command Button
  4. txtSelectedFile is a Text Box
  5. Label10 is a Image Control
  6. ShippedDate is a Text Box
  7. Label16 is a Image Control
  8. cboTest is a Combo Box
  9. Label15 is a Image Control
  10. Command17 is a Command Button
  11. Command18 is a Command Button
  12. imgTest is an Image Control
  13. chkImage is a Check Box
  14. Label21 is a Image Control
  15. Command22 is a Command Button
  16. Text25 is a Text Box
  17. Don't really care!
  18. Don't really care!
  19. Label29 is a Image Control
  20.  
Jan 30 '09 #5

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

Similar topics

7
by: Ivo | last post by:
How do I make the magic 'this' variable refer to an object of my choice, in a string of code which is to be eval'ed? Say, I have an object, an array with four elements: var myobject = ; and a...
3
by: Joshua Ammann | last post by:
Hi, (Using Access 2000) I have two tables, similar to Customers and Orders. (Not an exact parallel, but works for this example.) On a form showing customer data, there is a tab control. One...
8
by: jan Veenstra | last post by:
Hi, I am having two problems with Access 97. These '2 problems are posted seperately in this newsgroup. Here's the first: I have a form with lots of similar textboxes and I have a procedure...
0
by: ad | last post by:
I drag a Web User Control to my Web form. I want to change the text of a TexBox control in program. But I found I can refer the TexBox in that User control. How can we refer the confrols in a...
1
by: Paul | last post by:
I have a MDI container form "frmParent". On that form there is a tabstrip control with 2 pages. On one of those pages there is a textbox and a button. When the user clicks on the button a...
2
by: Dean Slindee | last post by:
Is there any way to refer to the .text property of a status bar panel thru object syntax, like below (the inner "for" does not work): Public Function FormStatusBarPaint(ByVal frm As Form)...
10
by: Bill Nguyen | last post by:
I have several textbox controls in a form,. I name them txt1, txt2, ... txt10. How dow I refer to them in a loop to get the value in text proerty of each control? For x = 1 to 10 value =...
4
by: Lysander | last post by:
I need a way of finding the name of the active control on a form. You can use currentdb() to refer to the current database You can use Me to refer to the active form or report. I need a...
12
EntryTeam
by: EntryTeam | last post by:
Hello every1. I'm trying to get OpenGL functions working inside windows forms, using #develop (SharpDevelop), which is great. I have this tutorial (in russian) and two files attached to it:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.