Reference to Control in other Form in SetProperty Macro Action (1 Viewer)

ProgAcc

New member
Local time
Today, 16:49
Joined
May 8, 2020
Messages
9
Hello,

I am trying to set the Value of a DropDown with a Macro. It does not work, giving me the error: "The control name XXXX is misspelled or refers to a control that doesnt exist". So I simplified it to test changing the control on the same form.
If I fill:
Code:
SetProperty
    Control Name:    cboFunction
    Property:        Value
    Value:            ABC
it works and changes the value of the DropDown. But as soon as I try to reference the object with its complete path it does not work anymore. In the examples I have seen online it seems it should work with: [Forms]![Employee_Analysis]![cboFunction]. However it doesn't. I have also tried:
Forms!Employee_Analysis!cboFunction
[Forms].[Employee_Analysis].[cboFunction]
Forms!Employee_Analysis!cboFunction
Nothing works. Why? How can you reference a control that is on a different Form inside of a Macro Action?

Thanks. I attach the error message.
 

Attachments

  • accerror.png
    accerror.png
    8.6 KB · Views: 306

Minty

AWF VIP
Local time
Today, 15:49
Joined
Jul 26, 2013
Messages
10,354
I'm afraid most people on here don't use macro's preferring VBA as it's much more flexible. However, the format you have used looks very familiar.
This page http://access.mvps.org/access/forms/frm0031.htm gives you the correct format for VBA and it looks like you have tried the correct syntax.


Forms!Mainform!ControlName

Maybe it's not possible in a macro. Is your combo on a sub form?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:49
Joined
Jul 9, 2003
Messages
16,244
Nothing works. Why? How can you reference a control that is on a different Form inside of a Macro Action?

If Form "Employee_Analysis" is closed, it won't work...
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:49
Joined
Sep 21, 2011
Messages
14,044
From the Help in 2007


Control Name
Type the name of the field or control for which you want to set the property value. Use only the control name, not the full syntax. Leave this argument blank to set the property for the current form or report​
Try selecting the form first?
 

ProgAcc

New member
Local time
Today, 16:49
Joined
May 8, 2020
Messages
9
Hello, thanks for the replies.
Yes, I know but for VBA you have issues with security policies of the company etc. The Macro Actions work without special rights.
@Minty: Yes, judging from how you reference the different objects in Access I have tried all syntax possible.
@Uncle Gizmo: Employee_Analysis is NOT closed. Indeed to really isolate the problem I am first trying to get it to work on the same Form, i.e. setting the property of cboFunction which is set ON the current open Form. So the button and the DropDown are on the same form.
@Gasman: Yes, I have already seen that help file. And again, it works if I only mention the Name of the cboFunctino Combobox. BUT only if it is in the same form. Even when I open the new form and select it and then only write the name without the ! etc. it still does not work.
 

ProgAcc

New member
Local time
Today, 16:49
Joined
May 8, 2020
Messages
9
  • "In Access desktop databases, you can use the SetProperty action in a stand-alone macro only if you precede it with an action that selects the form or report containing the control for which you are setting the property. If the form or report is not open, you can use the OpenForm or OpenReport action to open and select it. If the form or report is already open, you can use the SelectObject action to select it. You can then use the SetProperty action to set the property. Selecting the object is not necessary if you use the SetProperty action in a macro which is embedded in a control on the same form or report as the control for which you are setting the property."

I am getting closer to a solution. So indeed you cannot use the usual Syntax you can only use the name and then have to select it. However, I have done it like that now (open the form, select it, then only mention the Combobox Name by itself (see picture). However I STILL get the error message. BUT when I single step through the Macro, it does work. which is super weird.
 

Attachments

  • accscreen.png
    accscreen.png
    25 KB · Views: 375

Gasman

Enthusiastic Amateur
Local time
Today, 15:49
Joined
Sep 21, 2011
Messages
14,044
Well I know I only have 2007, but the only properties it allows me is not a Value property.?
I would have thought you should be using SetVallue ?, that works for me and you can use full form name and control path?
 

ProgAcc

New member
Local time
Today, 16:49
Joined
May 8, 2020
Messages
9
So yes, it seems the Form must be open, but the Macro must not necessarily be in the Form. I created a Macro outside of a Form, then let the Macro open the Form in question and change the value of the Combobox. THAT WORKS! Weirdly enough, when I go then into the other form and assign that Macro (the one that works) to the button (i.e. via RunMacro Macro Action), then it does not work anymore and gives the error I already shared.
So it seems that even when you run a Macro that opens the right Form where the Comobobox is, if it is run from a different Form it ALWAYS tries to look for that Combobox inside of its own Form. That doesnt make any sense to me and also does not fit with the Documentation MS provides...
Any workaround ideas?
 

Gasman

Enthusiastic Amateur
Local time
Today, 15:49
Joined
Sep 21, 2011
Messages
14,044
Well I managed to get SetValue to work from FormA for the control on FormB.?

Do you have that command in your version.?
Fom being open is pretty much a given?

I get the opposite. If I run the macro from a button in the form with the control it works. If I try from another form I get error 2950. That happens whether I run it manually or from a button, stepped or not stepped.

However that might be down to my version.?

The only thing I have used macroes for is batch processes, and even then that was when I knew less VBA than I know now. :D
 

Users who are viewing this thread

Top Bottom