My Assistant
![]()
Custom Search
|
![]() ![]() |
![]() |
![]() Post#1 | |
Posts: 546 Joined: 26-May 11 ![]() | Hi, I'm wondering if there's a VBA command that'll read back to me the type of object the code runs on, ie: form or report. (I may be misusing the word 'object' here.) Basically I want to be able to throw up a message box that includes the object type. Eg: I use Me.Name to get the name of the object, eg: "frmEmployees" but I want to also show that it's a Form. Thanks, Toby. This post has been edited by fizzy1: Nov 14 2019, 02:21 PM -------------------- thanks, fizzy1. |
![]() Post#2 | |
![]() UA Moderator Posts: 76,863 Joined: 19-June 07 From: SunnySandyEggo ![]() | Hi Toby. Are you referring to a public function? If so, you might try examining the stack if there's any info there you could use. Or, maybe you could simply add another argument to your procedure to pass the object type when it is called. Just a thought... -------------------- Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas Access Website | Access Blog | Email |
![]() Post#3 | |
Posts: 546 Joined: 26-May 11 ![]() | It'll be in either a public or private function or sub inside a form or a report. -------------------- thanks, fizzy1. |
![]() Post#4 | |
![]() UtterAccess VIP Posts: 9,839 Joined: 11-March 05 From: Maryland ![]() | If the sub will be in the report/form, you wouldn't need to know the type, just include it in the sub on the form/report. Now, if you're talking a public sub in a module that any report/form would be able to call, just pass a variable identifying if it is a report/form calling it. -------------------- William “We're run by the Pentagon, we're run by Madison Avenue, we're run by television, and as long as we accept those things and don't revolt we'll have to go along with the stream to the eventual avalanche" |
![]() Post#5 | |
Posts: 546 Joined: 26-May 11 ![]() | Reason I'm trying / wanting to do this is because I'm trying to make a universal error handler that I can use in a form, report, module that helps tell me where the error came from. -------------------- thanks, fizzy1. |
![]() Post#6 | |
![]() UtterAccess VIP Posts: 9,839 Joined: 11-March 05 From: Maryland ![]() | I understand. However, I still believe you are going to have to pass the object type to the function. However, rather than reinvent the whole wheel, why don't you check out these examples and modify as needed: Crash Reporter All Inclusive Error Handling .::. Error Logging .::. -------------------- William “We're run by the Pentagon, we're run by Madison Avenue, we're run by television, and as long as we accept those things and don't revolt we'll have to go along with the stream to the eventual avalanche" |
![]() Post#7 | |
![]() UA Moderator Posts: 76,863 Joined: 19-June 07 From: SunnySandyEggo ![]() | QUOTE (fizzy1) Reason I'm trying / wanting to do this is because I'm trying to make a universal error handler that I can use in a form, report, module that helps tell me where the error came from. Hi Toby. Doesn't that already exists somewhere? Do you really need to reinvent it? For example, take a look at this one. I'm sure there are other examples, if that doesn't work for you.-------------------- Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas Access Website | Access Blog | Email |
![]() Post#8 | |
![]() UtterAccess VIP Posts: 11,279 Joined: 10-February 04 From: South Charleston, WV ![]() | -------------------- Robert Crouser |
![]() Post#9 | |
Posts: 546 Joined: 26-May 11 ![]() | I'm not trying to build a new error handler so much as tweak the error message info that is returned with an existing error handler (coming from MZ Tools). I was really just hoping to get back "Form" or "Module" that I could place into my message. From what I can see MZ Tools provides a parameter that includes that info AND the name of the procedure as static text. Instead of that I was hoping to make it dynamic so eg: in the case where I rename a form I don't have to go through and replace text in several places of every error handler. Trying to make things more efficient we've all combined probably put in more time than this was worth, sorry. Anyway, the Application.CurrentObjectName did provide some of the solution but it returns an integer, I was hoping for a string of the name. THat might be the best I can get. -------------------- thanks, fizzy1. |
![]() Post#10 | |
![]() UtterAccess VIP Posts: 11,279 Joined: 10-February 04 From: South Charleston, WV ![]() | Yes, you will have to determine the object type. Current object type. -------------------- Robert Crouser |
![]() Post#11 | |
![]() UA Moderator Posts: 76,863 Joined: 19-June 07 From: SunnySandyEggo ![]() | CurrentObjectName gives me the name, but only for the parent object. For example, if I put that code on a button on a form, I get the name of the form, not of the button. Not sure if that's good enough for you. -------------------- Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas Access Website | Access Blog | Email |
![]() Post#12 | |
![]() UA Moderator Posts: 76,863 Joined: 19-June 07 From: SunnySandyEggo ![]() | Ah, even worse... If I had a form open and run a procedure in a module from the Immediate Window, I still get the name of the form when I expected to get the name of the module. Not good... -------------------- Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas Access Website | Access Blog | Email |
![]() Post#13 | |
Posts: 546 Joined: 26-May 11 ![]() | Yes, you will have to determine the object type. Current object type. Robert, is there some command that will bring back the name, or will I need to do something like make an enum table and then DLOOKUP the value from there? -------------------- thanks, fizzy1. |
![]() Post#14 | |
![]() UtterAccess VIP Posts: 11,279 Joined: 10-February 04 From: South Charleston, WV ![]() | How often is a user going to run a procedure from the immediate window? As far as I know there is no way to get it to say "form" instead of "2". So, yes, one way would be to make a little table and do a Dlookup. Another way would be a function with a SELECT CASE. But I'd go with the table. Not difficult. -------------------- Robert Crouser |
![]() Post#15 | |
![]() UA Moderator Posts: 76,863 Joined: 19-June 07 From: SunnySandyEggo ![]() | Hi. That was just a quick test. I imagine if I click on a button on a form that calls a function in a module but the module errors out, then I bet CurrentObjectName will still say the Form instead of the Module. -------------------- Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas Access Website | Access Blog | Email |
![]() Post#16 | |
Posts: 546 Joined: 26-May 11 ![]() | Thanks all, looks like I have the answer. -------------------- thanks, fizzy1. |
![]() Post#17 | |
![]() UA Moderator Posts: 76,863 Joined: 19-June 07 From: SunnySandyEggo ![]() | QUOTE (fizzy1) Thanks all, looks like I have the answer. Just to make sure I am clear, is the answer "there's no way to do it," or is it by using the CurrentObjectName and CurrentObjectType? Sorry if I'm a little confused. Thanks.-------------------- Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas Access Website | Access Blog | Email |
![]() Post#18 | |
![]() UtterAccess VIP Posts: 11,279 Joined: 10-February 04 From: South Charleston, WV ![]() | CurrentObjectType + table of types, it would seem. -------------------- Robert Crouser |
![]() Post#19 | |
![]() Posts: 651 Joined: 26-May 15 From: The middle of Germany ![]() | QUOTE Eg: I use Me.Name to get the name of the object, eg: "frmEmployees" but I want to also show that it's a Form. CODE MsgBox TypeName(Me) -------------------- |
![]()
Custom Search
|
![]() | Search Top Lo-Fi | 10th December 2019 - 09:51 PM |