Is it possible to bind form controls to VBA properties? - ms-access

I am currently updating an MS-Access legacy project. In a form I want to bind some controls to VBA properties (Property Let and Property Get), similar to the way it is done in WPF. Is this posssible? We are using Access 2007.

The ControlSource of a control can be a function:
=MyFunctionReadingSomeProperty([SomeParameter])
so if you can manage to build such a function, the answer is Yes.
However, the function is read-only, so if you want to set a property, the function must be able to do that using one (or more) parameters.
If you omit the parameter:
=MyFunctionReadingSomeProperty()
the function will be called only once, when the form loads.

Related

Get a selected value from a slate code sandbox

I'm trying to make a dropdown list with the code sandbox in the palantir slate, but I can't capture the selected value of the button in a function like the existing dropdown button, is there any way to capture this value with the code sandbox?
This is my code sandbox button
I am trying to capture the selected button value from this function tab
I am new to stack overflow, if you need more information just let me know, I am grateful to everyone who has offered to help me.
I tried to capture the value with selectedValues but apparently this option does not exist. I also tried with javascript for "document.getElementById("standard-select");"
but the console always returns undefined.
You want to get a value from the Code Sandbox to the Slate context.
You can follow this : https://www.palantir.com/docs/foundry/slate/widgets-advanced/#setstate
In short, You need to use the state of the Code Sandbox widget :
In the "Interaction" tab of the Code Sandbox, you need to specify an arbitrary state's variable, for instance : {"dropdownValue": "default_value"}
In your custom JS in Code Sandbox, you will store the value of interest (the value of your dropdown, for instance whenever it changes) in the state of the Code sandbox SlateFunctions.setState("dropdownValue", 4)
In your Slate's function, you can access the Code Sandbox state as any other variable : return {{w_mycodesandbox.state.dropdownValue}}
Whenever you call setState from your custom JS, you update the state, hence the variable the Slate function depends on, and dependencies will run as expected.
We can get a selected value from a Slate code sandbox by using the getSelectedValue() method. This method returns an object containing the currently selected value from the Slate code sandbox. The object contains the value, type, and range for the selection.

Is it possible to change the title property of an object via a derived value from an edit form in Foundry?

I created an object that is backed by a Foundry Form and I would like to provide a user to change the properties of that object. I linked the form to the object and created a title property that is a hidden/ derived value in the object creation form. A user can edit property a and property b and the title of the object will be ab.
When the user updates the object in the edit form the title does not update. Is there a configuration I need to change?
Yes, this is possible. There's actually two ways to achieve this, I'll list them in order of my preference:
Using an action
The modern way of achieving this is to use an action. Actions allow you to flexibly "intercept" events like writes from users and do extra actions (hence the name) or prevent things from happening. They are a fairly new feature in foundry.
The basic concept is that you write a little piece of code (a function on an object) that gets executed when the object is modified. The function can then modify the object further or prevent the modification.
This is very flexible, because it will allow you to automatically update the title of the object regardless of how and when the object was edited. You can also apply more complex logic to derive the title from e.g. multiple properties with fallbacks, or modify a property in a certain way before you put it into the title, et cetera.
The drawback is that this requires you to write some code.
On your stack, if you navigate to https://www.palantir.com/docs/foundry/functions/use-functions/#actions you will find an introduction on how to get started with actions. The example solves the exact use-case you're asking for.
Using form templates
Another approach that's simpler and does not require writing any code, but is much less flexible, is to use a template in the form. You can create a template form widget that's invisible, and is automatically populated by values from other form fields.
The advantage is that this is very easy and quick to set up, but the disadvantage is that it will only apply when the object is edited through the form, and you can really only do concatenation, not much else.
It sounds like this is what you attempted to do, and I believe this should work. If it doesn't, I would check the following things:
make the template visible to see that it gets filled out like you expect it to
make sure the template is set to store its response into the right property on the object
make sure the user is using the form to edit the object, not some other way (like editing the property directly in hubble)

Relative name to get information from Form in MS Access

I would like to know if it is possible in a Saved Query on MS Access to use WHERE clause getting value from a Form independent of MS Access installed language?
In a MS SQL QUERY WHERE clause that should be equal to a text in a form, I wrote it like this
= Form!Form_name!text_name
This work fine if all user have MS English version installed, however, this is not true in my case, as some users have a Portuguese version. In their version, the right way to call the same syntax should be:
= Formulários!Form_name!text_name
So, the problem is that Access does not recognize this considering language version. Due to this, if a user with Portuguese version try to run the query, it will pop up an insert box.
I've look throughout many sources but none could help me to solve this.
Thank you all in advance!
I can't test this as I don't have a portuguese version of Access but I avoid calls to form parameters because they are brittle. For instance the form has to be open or the query fails in wierd ways. If I must use a form's parameter I wrap the parameter in a public function (usually in that forms code behind). A public function usually gets picked up by intellisense even in the designer but a public variable does not.
My style is to synthesize a property with a private global scope variable and public get and set functions. Then in the designer you can call: get-myforms-property instead of Form!Form_name!text_name. When the form opens and closes I usually call set-myforms-property and set it to be equal to the actual form property.
In this way you also get the advantages of wrapping. For instance you can choose what value to return when the form is closed rather than just having the query fail.

How to use textbox value as an SQL connection string

I am using VB.net in creating this application. My idea is when the main form loaded, there is another form with textboxes for the user to initialize connection to the sql server, and use that textbox value in calling the database for query.
Now, my problem is then main form closes the value in the textbox will be erased, and i have to type it again. When connecting for an SQL Server over the LAN, does it have the same process?
You should not be referencing controls' values for logical uses like that; instead use the value in the control to populate a more persistent program entity, such as a settings object.
In your particular case, with VB.net (and presumably WinForms), showing connection form with ShowDialog() allows the form to persist after it has been closed. You can add a public property to the form to expose the user-entered value to the code that called it, and DialogResult of OK when the user indicates the value is accepted (usually through a button click).
I'd provide a code example, but I've been deep in C# for more than a few months now and my VB.Net is getting rusty.

ms-access vba Eval function behavior

I have a public function in an Access form
Public Function PopupProcess() as long
MsgBox Me.ActiveControl
PopupProcess = 1
End Function
When I call
eval("forms('MyForm').popupprocess")
it shows a message box 2 times. Does anybody know why it does that?
I Have Access 2003 with SP3.
EDIT : Main idea is to call function from that form for Custom Commandbar control OnAction.
Maybe you have better way to call function from a form for commandbar control.
This is a very long standing bug that’s been around since the days of access 97, (about 4-5 versions of access).
The solution here is to NEVER use the forms qualifier, simply place the following in your on action event, and you’ll be just fine
=PopUpProcess()
Note that you must precede it with=, and the suffix must have the brackets ()
Keep in mind that you can actually use behavior to your advantage. The function that runs is going to be from the form that currently has the focus on the screen. That means you can have different forms with the same name of the function, and whichever form has the focus, that function with that name will run from that forms code module.
Even better, if one of the forms does not have that function as public in the forms code module, then the function in a standard code module is used. So you might have nine forms, that all use the standard one function in the main standard code module. However, the 10th form might need to run special code, so you simply place that function code in the form’s code module as public and it will run in place of the public on in the standard code module.
This approach allows you to build a single custom menu bar that applies to many different forms, but those many forms will run different code on from that custom menu bar. This also encourages you to place the menu code in the form it belongs.
So to solve your problem, simply don’t use a form’s qualifier, and use the above format.
Note that you can pass Parameters from those functions also, for example
=PopUpProcess(‘hello’)
And then declare the function as:
Public Function PopUpProcess(strParm as string)
Keep in mind that the function and syntax and all of what I stated above also applies to when you use the on action in a ribbon for access 2007.
No idea. What happens if you call it like this?
Call Forms("MyForm").PopupProcess
Try using the CallByName function, instead of eval, to call your function. It should only fire your function once, and it will still allow you to parameterize the form name and the function or sub name:
CallByName Forms("MyForm"), "PopupProcess", VbMethod