Return the name of the object I click on in a form

Hi,

How do I go about returning the name of an object on a form. For example if 
I set the "On Click" event procedure on a rectangle object to return:

MsgBox Me.Name 

I get the form name. What I want to  do is click on the object and be abe to 
reference it's properties such as Tag to run other code based in these values.

As always any assistance is greatly appreciated.

Regards,

John Dumay
0
Utf
1/17/2008 7:46:04 PM
access 16762 articles. 3 followers. Follow

4 Replies
713 Views

Similar Articles

[PageSpeed] 32

For the name of the control try
Screen.ActiveControl.Name

For the control itself use
Screen.ActiveControl

-- 

AG
Email: discussATadhdataDOTcom
"John Dumay" <JohnDumay@discussions.microsoft.com> wrote in message 
news:51404901-2AF3-4386-A46F-DC06D35627CA@microsoft.com...
> Hi,
>
> How do I go about returning the name of an object on a form. For example 
> if
> I set the "On Click" event procedure on a rectangle object to return:
>
> MsgBox Me.Name
>
> I get the form name. What I want to  do is click on the object and be abe 
> to
> reference it's properties such as Tag to run other code based in these 
> values.
>
> As always any assistance is greatly appreciated.
>
> Regards,
>
> John Dumay 


0
AG
1/17/2008 8:49:19 PM
Hi AG,

Thanks for the reply. Yes I have tried that option but the Rectangle object 
cannot get the focus so it cannot return the name of the clicked object. 
Instead it returns the name of the object which has focus. (In my case a 
toggle button)

Regards,

John

"AG" wrote:

> For the name of the control try
> Screen.ActiveControl.Name
> 
> For the control itself use
> Screen.ActiveControl
> 
> -- 
> 
> AG
> Email: discussATadhdataDOTcom
> "John Dumay" <JohnDumay@discussions.microsoft.com> wrote in message 
> news:51404901-2AF3-4386-A46F-DC06D35627CA@microsoft.com...
> > Hi,
> >
> > How do I go about returning the name of an object on a form. For example 
> > if
> > I set the "On Click" event procedure on a rectangle object to return:
> >
> > MsgBox Me.Name
> >
> > I get the form name. What I want to  do is click on the object and be abe 
> > to
> > reference it's properties such as Tag to run other code based in these 
> > values.
> >
> > As always any assistance is greatly appreciated.
> >
> > Regards,
> >
> > John Dumay 
> 
> 
> 
0
Utf
1/17/2008 9:39:01 PM
All I can think of would be to pass the name of the control to your 
procedure.

For instance:
Private Sub Rectangle1_Click()
    Call YourControlFunction("Box44")    'for controls that can't get focus, 
pass the name
End Sub

Private Sub TextBox1_Click()
    Call YourControlFunction    'for controls that can get focus, no need to 
pass its name
End Sub

If you have a lot of controls, you can save some work by selecting all the 
controls that can get focus and putting '=YourControlFunction()' in the 'On 
Click' event.

Private Function YourControlFunction(Optional byval strControlName As String 
= "")
Dim ctL as Access.Control
    If strControlName <> "" Then
        Set ctL = Me(strControlName)
    Else
        Set ctL = Screen.ActiveControl
    End If
    If ctL.ControlType = acTextBox Then
        Do something
    ElseIf ctL.ControlType = acComboBox Then
        Do something else
    End If
End Function
-- 

AG
Email: discussATadhdataDOTcom
"John Dumay" <JohnDumay@discussions.microsoft.com> wrote in message 
news:53EAD792-6125-4259-B70E-C24051BCB715@microsoft.com...
> Hi AG,
>
> Thanks for the reply. Yes I have tried that option but the Rectangle 
> object
> cannot get the focus so it cannot return the name of the clicked object.
> Instead it returns the name of the object which has focus. (In my case a
> toggle button)
>
> Regards,
>
> John
>
> "AG" wrote:
>
>> For the name of the control try
>> Screen.ActiveControl.Name
>>
>> For the control itself use
>> Screen.ActiveControl
>>
>> -- 
>>
>> AG
>> Email: discussATadhdataDOTcom
>> "John Dumay" <JohnDumay@discussions.microsoft.com> wrote in message
>> news:51404901-2AF3-4386-A46F-DC06D35627CA@microsoft.com...
>> > Hi,
>> >
>> > How do I go about returning the name of an object on a form. For 
>> > example
>> > if
>> > I set the "On Click" event procedure on a rectangle object to return:
>> >
>> > MsgBox Me.Name
>> >
>> > I get the form name. What I want to  do is click on the object and be 
>> > abe
>> > to
>> > reference it's properties such as Tag to run other code based in these
>> > values.
>> >
>> > As always any assistance is greatly appreciated.
>> >
>> > Regards,
>> >
>> > John Dumay
>>
>>
>> 


0
AG
1/18/2008 2:40:00 AM
Hi AG,

Looks like a perfectly good solution. Will give it a go and let you know.

Thanks for your assistance.

Regards,

John Dumay

"AG" wrote:

> All I can think of would be to pass the name of the control to your 
> procedure.
> 
> For instance:
> Private Sub Rectangle1_Click()
>     Call YourControlFunction("Box44")    'for controls that can't get focus, 
> pass the name
> End Sub
> 
> Private Sub TextBox1_Click()
>     Call YourControlFunction    'for controls that can get focus, no need to 
> pass its name
> End Sub
> 
> If you have a lot of controls, you can save some work by selecting all the 
> controls that can get focus and putting '=YourControlFunction()' in the 'On 
> Click' event.
> 
> Private Function YourControlFunction(Optional byval strControlName As String 
> = "")
> Dim ctL as Access.Control
>     If strControlName <> "" Then
>         Set ctL = Me(strControlName)
>     Else
>         Set ctL = Screen.ActiveControl
>     End If
>     If ctL.ControlType = acTextBox Then
>         Do something
>     ElseIf ctL.ControlType = acComboBox Then
>         Do something else
>     End If
> End Function
> -- 
> 
> AG
> Email: discussATadhdataDOTcom
> "John Dumay" <JohnDumay@discussions.microsoft.com> wrote in message 
> news:53EAD792-6125-4259-B70E-C24051BCB715@microsoft.com...
> > Hi AG,
> >
> > Thanks for the reply. Yes I have tried that option but the Rectangle 
> > object
> > cannot get the focus so it cannot return the name of the clicked object.
> > Instead it returns the name of the object which has focus. (In my case a
> > toggle button)
> >
> > Regards,
> >
> > John
> >
> > "AG" wrote:
> >
> >> For the name of the control try
> >> Screen.ActiveControl.Name
> >>
> >> For the control itself use
> >> Screen.ActiveControl
> >>
> >> -- 
> >>
> >> AG
> >> Email: discussATadhdataDOTcom
> >> "John Dumay" <JohnDumay@discussions.microsoft.com> wrote in message
> >> news:51404901-2AF3-4386-A46F-DC06D35627CA@microsoft.com...
> >> > Hi,
> >> >
> >> > How do I go about returning the name of an object on a form. For 
> >> > example
> >> > if
> >> > I set the "On Click" event procedure on a rectangle object to return:
> >> >
> >> > MsgBox Me.Name
> >> >
> >> > I get the form name. What I want to  do is click on the object and be 
> >> > abe
> >> > to
> >> > reference it's properties such as Tag to run other code based in these
> >> > values.
> >> >
> >> > As always any assistance is greatly appreciated.
> >> >
> >> > Regards,
> >> >
> >> > John Dumay
> >>
> >>
> >> 
> 
> 
> 
0
Utf
1/18/2008 4:51:01 AM
Reply:

Similar Artilces:

Click in cell w/ formula and get colors in referenced cells
Hi, When you click in a cell with a formula, Excel will then put color around the cells that are referenced. Somehow I turned that feature off. Now I do not get colors in th other cells. Where is that option to turn it back on???? I've looke and looked but I just can't find that option. Thanks for the help -- albea ----------------------------------------------------------------------- albean's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2875 View this thread: http://www.excelforum.com/showthread.php?threadid=48436 ...

Merging List w/ a Form
Can anyone assist me with merging a form created in Excel with a database (or list) also created in Excel? I know how to merge an Excel worksheet to be used as a database for Word in the Mail Merge command, but my FORM, with which I am trying to merge my database, was created in Excel and needs to remain under its format (not be converted to Word). I am filtering the information I need from the database to be imported to the Excel Form. Any help would be appreciated. Thank-you. If you're trying to display information from one record in the database, there are sample files here...

OWA returns HTTP/1.1 503 Service Unavailable
Outlook Web Access used to work fine, but now users are receiving the following message HTTP/1.1 503 Service Unavailable Users can access the OWA page, but after typing in credentials and clicking "Log On" the above error is returned. If the incorrect credentials are entered the "You could not be logged on to Outlook Web Access" message is received. This tells me I'm authenticating fine but whatever the next step is it is failing. There are no error messages in event viewer. Any recommendations of what to look at next? The OWA Exchange 2003 Server sits on a ...

Formatting multiple object types in output from a function?
I'm stumped on this one, and have searched and searched for a solution or how-to with no luck. Perhaps it just can't be done. I have a function that may or may not return objects of multiple types. I've setup the type and formatting information for each of the individual types in format.ps1xml files, and when only 1 type is returned by the function the formatting works as I would expect. However, if two or more types are returned by the function, only the formatting for the first object type is applied and then the other types are displayed however PoSH deems ap...

Filter Report by Form
I'm using the following code from the wonderful Allen Browne which works perfectly in an either or scenario (either by Start/End Date(s) OR filtering by client name; but I don't know what syntax to use to filter by Start/End date(s) AND anything typed in the client name field. I'm sure it's easy but I can't get my head around it. I appreciate any and all assistance!! Private Sub cmdPreview_Click() 'On Error GoTo Err_Handler 'Remove the single quote from start of this line once you have it working. 'Purpose: Filter a report to a date r...

Excel docs won't open from clicking file
I have a strange issue us Excel 2002. When I double-click on an excel document it only open the excel program and not the doc. I can then go to file|open and open it just fine and work on it etc. Excel seems to be OK other than this strange issue. Word and the other office programs don't do this at all??? I have checked and verified all folder options | files types, their associated open commands etc. Any ideas would be greatly appreciated, Thanks- Hi Have a look at Tools/Option/General and uncheck 'Ignore other applications' if it's checked. Andy. "jayman" ...

Button on Form to Run Report based on Query with Parameters
Hi Guys. I am busy working on a stock control database (and job control). When I have a Form Open, it shows several fields, including JobID (Which is the PK for that job) (frm_Invoicing) I also have a Query that when Run, it prompts for the JobIDNo. (qry_CustJobsInvStock) I have a report based on that query. (rpt_CustJobsInvStock) I have added a button onto the form (onclick -> DoCmd.OpenReport) to open and automatically print the report, But I just cannot figure out how to get it to get my JobID from the form, and to Automatically add it as a Parameter for the que...

Why can't I click on the signature section to change my signature
When I go into tools, options, and then the mail format tab, the signature option is greyed out and I can't click on it. I therefore cant edit my existing sugnature or create a new one. I've tried changing the format options to compose the message in, and still no luck. Are you perhaps in a corporate environment? Then you mail admin might have disabled that option as a corporate policy. Ask him/her or your manager for more information. -- Robert Sparnaaij [MVP-Outlook] Coauthor, Configuring Microsoft Outlook 2003 http://www.howto-outlook.com/ Outlook FAQ, HowTo, ...

Center Access2007 Form in the middle of access Main Window
Thank You Is there any easy way to center access 2007 forms in the middle of the screen (Monitor) or access main window. and give me good result Hello, I think there is no built in feature to achieve this goal. You may need to create a new form and configure it as the main window. You could enumerate forms and create buttons etc to open forms from this main form. For example, you could use hte following code enumerate forms in your database: Dim db As Database Set db = CurrentDb Set cntContainer = db.Containers("Forms") For Each doc In cntContainer.Documents Str...

name appearing in the outgoing mail
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Email Client: pop I would like to change the way the name in each of my accounts shows up in sent emails. I have changed the account settings but the old name still shows up. Any suggestions? <br> Thanks. On 2010-05-04 16:45:26 -0400, Bila@officeformac.com said: > I would like to change the way the name in each of my accounts shows up > in sent emails. I have changed the account settings but the old name > still shows up. Any suggestions? Well if you have indeed changed the name prop...

How to reference workbook name in hyperlink formula?
In order to simplify the maintenance of workbook formulas I need to reference workbook name in hyperlink formula =[myWorkbok.xls]mySheet!$E4 in this way =[A1]mySheet!$E4 given the file name stored in cell A1 Cell A1 : myWorkbook How do I write the formula to make it work? Will it work even if the referenced workbook is closed? Regards Frank Krogh The function you'd want to use is =indirect(). But =indirect() won't work if the sending file is closed. Laurent Longre has an addin (morefunc.xll) at: http://xcell05.free.fr/ or http://xcell05.free.fr/morefunc/english/index.htm ...

How can I compare the column names from 2 tables and output them?
I have a requirement to place an alert if the field does not exist in my table, tblStaging. Can any one guide me to reframe this query with error handling messages? I know it is not good practice to use select * but I need to do this as my columns\field names change each time. INSERT INTO tblStaging SELECT * FROM tbl_XL,tblDetails; Thank you -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/Forums.aspx/access-formscoding/201003/1 Access is a relational database. If your "table design" has the fields in your table(s) changing frequently,...

Printout Method
In building a form to allow users to print a "blank form" I've constructed as an Access Report, I'd like the user to be able to select the number of copies to print. It looks like the PrintOut Method would be a good choice for this, but I'm not smart enough to know quite how to get the "Copies" argument to get its input from the textbox on my form, where the user will enter the number of copies they'd like to print. Suggestions? -- Thanks, Croy Does the report have a record source? -- Duane Hookom Microsoft Access MVP If I have helped you, please help...

email form script to show email adresses of all recipients
I see there is a field in the attributes called torecipients but I cannot add it to the email form. Is there a way I can script this into the email form to show the email addresses of all of the recipients. My idea involved creting a new attribute called all_recipients and adding it to the form then doing a onchange for each of the to, cc, and bcc fields to update all_recipients. SO far it doesnt work. All the field returns is "undefined". Any help is greatly appreciated!!! ...

Changing the names of fields in tables after creating other object
I just leaned about the naming conventions after I have created my tables, reports and several queries. Can I change the name of fields in my tables (to remove the spaces and give them unique names ie not just last name but childlastname) without destroying the work I have done in queries, reports, and forms. Mary -- Positive Direction for Youth & Families, Inc. (www.pdfyinc.com) Possibly. If you are using a newer version of Access, say 2003 or 2007 AND you have Name Autocorrect, and all it's options, enabled, it MIGHT work. I found it somewhat buggy. Before you...

VBA to import 344 objects from 97 to 2003
I am looking to import a select list of tables, forms, queries, reports and macros from Access97 into Access2003. Yes this can be done by selecting each individual object, but I need to do this 5 or 6 more times before I do it for the final production copy. Pieter, Ken, and John have all been great resources in previous VBA questions, I would greatly appreciate any/all assistance. Thank you!!! The import dialog lets you select all items on the form. Since you're only talking 5 or 6 times, it's probably faster to do that, rather than bothering to write code to do it. -- Dou...

Fill Form And Get $5000 To Your Home.
Fill Form And Get $5000 To Your Home At http://ukcitygirls.co.cc Due to high security risks,i have hidden the cheque link in an image. in that website on left side below search box, click on image and enter your name and address where you want to receive your cheque. please don't tell to anyone. ...

Updated records in forms
Each record in a form is a work order. School, contractor, days of work, etc. I have a pop up calendar to select a week ending date for each record. Record 1's week ending date is Nov 13, 2009. Record 2's week ending date is Nov 20, 2009. When I change the date in record 2, it's changing the date in record 1. Each record's week ending date become all records' week ending date? Can I use a pop up calendar in a record and be able to retain the correct week ending date for each record. If so, how would I be able to accomplish this? Thanks for your inp...

requery subform from sub form
Thank you how can i requery subform from subform ? "a" <youb@hotmail.com> wrote in message news:%23R9c$8tSIHA.2000@TK2MSFTNGP05.phx.gbl... > Thank you > how can i requery subform from subform ? Me.Parent!Subform2ControlName.Form.ReQuery thank you the work correctly "Stuart McCall" <smccall@myunrealbox.com> wrote in message news:fl83eg$3o6$1$8300dec7@news.demon.co.uk... > "a" <youb@hotmail.com> wrote in message > news:%23R9c$8tSIHA.2000@TK2MSFTNGP05.phx.gbl... >> Thank you >> how can i requery subform from subfo...

Controls resize when clicked
In Excel 2002, activeX controls such as command buttons, combo boxes, check boxes and option buttons will display inaccurately until they receive focus. Fonts and symbols used in the control often appear distorted until clicked. For example, with the combobox, the dropdown arrow appears scrunched. With command buttons it looks like the height and width are both increased by 1 when clicked and then the button returns to the wrong size when another control receives the focus. This occurs on multiple machines running Office XP, with and without service packs 1 and 2 installed. The probl...

Exchange 2003 with wrong domain name
I was hoping someone could give me some advice on an issue we are having. We have an Exchange 2003 and DC(Windows 2003 Server) server behind a Cisco PIX 506e router. Everything works great, however the company that installed the servers for us, named our domain wrong. So our root domain is not correct. However, this has never been a problem until now. Now more and more companies are using some type of reverse lookup to make sure the domain name matches up with the IP address. Well, since our domain name was named wrong, the external address of our firewall, does not match our domain name. ...

How to read xml into dataset from xmlwriter object?
Hi, I have two Datagrids. >From the DG1, I read the content by DG1.WriteXml(xmlWriterObj...) Now, I would like to copy the content of xmlWriterObj into another datagrid I don't want to write the content of xmlWriterObj into a file rather keep them in memory. So, when I tried to use DG2.ReadXml(xmlWriterObj...), it erros out because this method expects xmlReader obj. How can I do this? Thanx, AceMonster wrote: > I have two Datagrids. >>From the DG1, I read the content by DG1.WriteXml(xmlWriterObj...) > Now, I would like to copy the content of xmlWriterObj into another...

Misplacement of objects on a sheet
In Excel 2007 when loading a workbook (originally created in Excel 2000), objects like text boxes, rectangles, etc will frequently be placed on the sheet in the wrong place. I have posted an example at http://65.243.151.82. Notice in the "Correct" screenshot the row of buttons. You can click any of the buttons (which correspond to sheet names) and go to that worksheet. The current active worksheet ("WA" in the example) is indicated by the red background text box filling the space of the button (and circled in the example). In the "Incorrect" example, notic...

Extra/incorrect names in "To" address drop-down list
After you have sent emails to recipients, Windows Mail "remembers" the names/email addresses. Unfortunately, if you send an email using an incorrectly typed email address it remembers it also. Therefore, when you type the first letter of the recipient you are sending a message, both the incorrect and correct address appears, which can be troublesome if the incorrect address is not apparent. How do you remove the incorrect address from the drop-down? Thanks in advance. "lawdog1881" <lawdog1881@discussions.microsoft.com> wrote in message news:C561E...

Date field behavior differs between forms
I have two forms with seemingly identical date fields. In one, if I place my cursor in the middle of it, the first number I type gets put in the far left of the field. In the field on the other form, if I place the cursor in the middle, it starts typing right where I am. Any ideas? I have thoroughly looked through the properties of each field and each form and I cannot find what is causing this behavior. I would love to get both of them to start placing typed characters at the far left instead of where the cursor is. Thanks! Check the Text Alignment property of both controls (not ...