Powerapps Visible function - ms-office

For some reason the Visible function in my Powerapps won't work I just wrote in OnSelect() Mail.Visible = false
The Mail is in this case a Textinput/ TextBox.
When I click on the button nothing happens. I can't find a documentation about it on the MS Website but I have in Powerapps a fuction called "Visible"

You need to create a variable in the button's (or another control) OnSelect property:
UpdateContext({ mailVisible: false })
And set the Visible property of the Mail control to mailVisible. You may need to initialize that variable to true, for example, in the screen's OnVisible property:
UpdateContext({ mailVisible: true })
PowerApps works similarly to Excel - you cannot, by an action, change directly the value of a cell (e.g., A1 = 42). But you can make the A1 cell reference another cell (say, =A4), so when you change the value of the cell A4, A1 will be updated as well. The same principle applies in PowerApps - you cannot change the value of a property from an action, but you can update the value that the property references.

Credit #SeaDude
This worked perfectly for me toggling the variable back and forth to show/hide a few layers.
Set(mailVisible, !mailVisible)

So I have a few items like this. I'm not sure if this is the BEST way but I know it works.
Set a variable on the app start:
App = Set(variable_visable, "");
Button code:
Onselect = Set(variable_visable.,"1");
Item that you want visible:
Visibility = If(variable_visable="1", true, false);
Edit: You can reset your variable at any point to hide that section.
Sometimes power apps fights you on things that seem correct.

The Visible will the condition that is true to make it show.
For example
If I have one TextBox named TextInput1 and I want a control to be visible when the Text entered = true it will be. For this example use a label.
Label1's visible function will be TextInput1.Text = "true"
This will show when the input text will be true. if it's false or anything else the label won't show. This is a very basic use of the visible but can be used in many ways.

In On select property of button you can't set any other control property directly.
you need to follow the steps as:
1- you need to set a boolean type variable on OnSelect of button e.g.
Set(varShowMail,false)
2- go to TextInput Mail and select its Visible property and assign the variable "varShowMail"
It will work 100%.

Set on visible of screen property UpdateContext({ Var_Visible: false})
set a variable on control "select" or "change" to true"UpdateContext({ Var_Visible: true})" and use the variable in other control visible property that you want to show or hide, if required you can use condition to set a variable to true or false

Related

Get ComboBoxItem from Combobox

In my universal windows Application I have below "xaml" :
<ComboBox Margin="8" Header="Language" x:Name="cmbLanguage" x:Uid="cmbLanguage" ItemsSource="{x:Bind Languages}" SelectionChanged="LanguageComboBox_SelectionChanged"/>
Now i need to iterate through my combobox and get the combobox items to disable some of them. How can i get access to the items from code behind?
Now i need to iterate through my combobox and get the combobox items to disable some of them. How can i get access to the items from code behind?
You could get ComboBoxItem with ContainerFromIndex method, and the set IsEnabled property to false or true, for more you could refer to the follow.
ComboBoxItem^ item = dynamic_cast<ComboBoxItem^>(cmbLanguage->ContainerFromIndex(CurrenIndex));
item->IsEnabled = false;

MS Access: Choosing Worksheet from Excel Workbook

I'm writing some code in MS Access and I reached to the point where user needs to choose on which worksheet of an Excel workbook there need to be performed some operation. I don't know, what name of this worksheet is or on which position it is placed.
I was thinking about a solution which will show user a form (as modal form) with listbox containing all sheets names'. When user click one of them form will show aside A1:J10 range (so user can choose the right one worksheet). After confirming choosen worksheet it will return as worksheet object.
Every thing was great untill I wanted to pass a object variable to the form. In openArgs I can only pass a string. I was even thinking about a class which will open this form but it's still no luck with passing object parameter.
I'm trying to avoid global/public variables.
Any ideas?
Assuming your object is wsObj, can't you just use wsObj.Name ?
Also have a look at wsObj.CodeName, which may be interesting as well.
There are many possibilities to send some value between objects.
A) Using Global vars into ACCESS Vba module
Global yourvariable As String
if you need some different value can use Variant, Single, etc.
B) Using Windows Register
To save value:
SaveSetting "yourprojectname", "Settings", "yourvariable", yourvalue
To retrieve value:
retvalue = GetSetting("yourprojectname", "Settings", "yourvariable", "your_default_value_if_not_exist")
C) Using OpenArg into Open Form command procedure
DoCmd.OpenForm "stDocName", acNormal, "filter_if_needed", "stlinkcriteria", acFormEdit, acWindowNormal, "arguments_forOpenArgs"
On destination form
Private Sub Form_Open(cancel as integer)
your_args=Me.OpenArgs
On all three possible solutions you can send more than one value using a chain with vars and values, an example:
myvar_mutiple="name=John Doe|address=Rua del Percebe 34|location=Madrid|phone=34 91 1234567"
On this example i used "pipe" (AltGr on key 1) char to separate each var=value
Then on destination procedure only need split each pair:
splitvar=Split(myvar_multiple,"|")
With this you obtain for each "splitvar" an element like "name=John Doe"
Do again an split with "=" to obtain variable an value. For each value you can reassign the result to a local vars.
Full code example:
if me.OpenArgs<>"" then
splitvar=Split(me.OpenArgs,"|")
for x=0 to ubound(splitvar)
tmpsplit=Split(splitvar(x),"=")
paramvars=tmpsplit(0)
paramvalue=tmpsplit(1)
select case paramvars
case "name"
stname=paramvalue
case "address"
straddress=paramvalue
case "location"
strlocation=paramvalue
case "phone"
strphone=paramvalue
end select
next
end if
Some recommendations that i use for this code "multiple vars":
- always use Low Case variable or change this:
paramvars=tmpsplit(0)
by
paramvars=lcase(tmpsplit(0))
-if you need to use "=" into value you can change by other alternative char or search the first "=" form left (i used this solution instead Split)
paramvars=trim(lcase(left(splitvar(x),len(splitvar(x))-(len(splitvar(x))-instr(splitvar(x),"="))-1)))
remember that you can send any value and can be converted on destination code. On this sample i use only String so you can use cLng or cInt etc.
Over your solution to select Sheet on excel from Access i think there are better alternatives.
IN the forms Module you can declare a property as object and then set that property once loaded. So in the form module
Option Explicit
Private myObj as object
Property Set DesiredWorksheet(o as object)
set myobj = o
End
and then in your code
Load myform
set myform.desiredworksheet = wsObj
myform.show
Ahh, sorry I was writing Excel not Access!!!
Docmd.openform f
f.desiredworksheet = ws.obj
docmd.openform f, windowmode:=acdialog
ought to work

Change value of check box when its name is the value of a variable

First post so I'll try my best to make it a good one (please tell me if I'm doing it wrong).I can't seem to write the code properly to change the value of a check box or option button on a sheet using a variable.
Suppose the name of the check box name is "Chk1", normally I would write :
Worksheets("AP-1").Chk1.value=X
Where X is (either True or False). Since it is a Loop, I use a range variable called FoundRange and it's value is the name of the check box, so I tried:
dim chkname as string
chkname=foundrange.value
Worksheets("AP-1").Chkname.value=X
I also tried
Worksheets("AP-1").CheckBoxes(chkname).Value = X
and
Worsheets("AP-1").Shapes(chkname).ControlFormat.Value=X
I also had a linked cell that I used to change the value, but when it writes either false or true in it, the check box becomes gray and I need to press F2+Enter in the linked cell to make the check box show the proper value. I also tried to select the linked cell after changing its value and use that code:
Application.SendKeys "{F2}"
Application.SendKeys "{ENTER}"
but it did not work.
Please help me :)
Based on your initial code, it must be an ActiveX control, not a Form one, so:
dim chkname as string
chkname=foundrange.value
Worksheets("AP-1").OLEObjects(Chkname).Object.value = X

What's the lifetime of Application.ScreenUpdating value in Excel 2010?

As far as I know Application.ScreenUpdating = true value is maintained until Application.ScreenUpdating = false is set. But what's the 'lifetime' of this value? Is it while the procedure where it's called starts and finish, while Worksheet is opened, or?
Made a class to keep ScreenUpdating value consistent to my needs:
Init class
set ScreenUpdating = False
At the end of procedure or in case of error restore the value to True.
The class handles this case ok.
Some times need the opposite:
Init class
set ScreenUpdating = True
At the end of procedure or in case of error restore the value to False.
I'm having trouble here; the class sets properly the value ScreenUpdating = false, but when the class gets the 'actual' value of ScreenUpdating it is always true. There are no other procedures or addins that could be changing the value.
Have prepared a test sheet to show the points above. Select the value for ScreenUpdating from the dropdown above the "suCaller" button.
Select False and press the button.
Value before setting False is True as expected.
Test data is filled from another procedure showing ScreenUpdating new value (False).
After data fill, the value is reset to True.
Press the button again and 'Actual' value is True as expected.
Do it many times and values should be fine.
Now Select True and press the button.
Value before setting True is True as expected (which is the value from above)
Test data is filled again showing ScreenUpdating new value (True)
After data fill, the value is reset to False.
Press the button again and 'Actual' value is True not False.
The class just negate the new value to define the restore value, so the result confuses me on the lifetime or how ScreenUpdating value should be set.
Am I doing something wrong in the class or missing some basic theory?
Class Module: ApplicationScreenUpdate
Test Module: Test
Test Sheet
TIA, Oscar.
So far as I'm aware this is behaviour is by design (but I don't have a quotable source for that).
While an experienced developer would expect the setting to remain, an inexperienced one would probably not realise what they'd done and would think that excel was broken if they tried to manually put data into the sheet after their macro completed.
Something you could try is to disable the application events as sometimes they can reset the value, also you may want to try writing a value after you set the updating to false but I suspect that value will appear after the macro is done.
Have found that the lifetime for ScreenUpdating or DisplayAlerts value, is the top procedure where the value was modified. At the end of the procedure; even if the value was set to false, the value for this properties ALWAYS is restored to TRUE.
On the other hand, EnableEvents or Calculation retains its value at the end of the procedure where the value was modified, been TRUE or FALSE.
Open this workbook and run the methods in the following order:
TestFalse
TestCurrentValues
TestValues
TestCurrentValues
RestoreValues
TestCurrentValues
After running each method, see values in sheet.
Cannot confirm wich application properties modify the value of other ones. But as James wrote, some change its own value 'by design'

Is it possible to create OptionButton Switch Effect?

Something like this:
Private Sub opt01_Click()
If opt01.Value = True Then
opt01.Value = False
Else
opt01.Value = True
End If
It would be suitable for my formDesign, instead of looking for and importing some similar small picture.
Because an OptionButton's value is always true when the Click event runs, you will need to store its desired value in a variable. Here is an example using a Form Control Option Button within a sheet named Option Button 1 on sheet 1. This method is stored in a module.
Private optionClicked As Boolean
Sub OptionButton1_Click()
Dim o As OptionButton
Set o = Sheets(1).Shapes("Option Button 1").OLEFormat.Object
o.Value = Not optionClicked
optionClicked = Not optionClicked
End Sub
Note however, that using this method, that clicking on any option button will make all other option buttons false. So to use multiple option buttons as check boxes, you will need to store the correct value of the option buttons (probably in an array)... and correct the values every time any option button is clicked.
Are you sure you can't use check boxes?

Resources