Same Form Control for New and Edit Mode in PowerApps
Today I want to talk about something extremely simple but I find is either not known or overlooked. In PowerApps, you use Form Controls to enter and edit data. These Form Controls have different Modes:
New – To add a New Item to your DataSource
Edit – To Edit an Existing Item in your DataSource
Display – To View data in your DataSource
I find a lot of people creating multiple Form Controls for each of these modes. While that might make sense if the data you want to show between the different modes is drastically different, most times I find that it’s the same. If that’s the case, then why not use one form control for all 3 modes? Thankfully you can do that fairly easily with the following functions:
EditForm(“Name of your Form Control”)
NewForm(“Name of your Form Control”)
ViewForm(“Name of your Form Control”)
You can call each of these functions and pass in the name of your Form Control to change the Mode of the control.
Here’s an example of how I used this in one of my PowerApps. I have a Project Initiation Form landing screen with an icon to add a new item and a Gallery control to edit an existing item. I used a Global Variable called “varMode” and set it to “Edit” when the Gallery Control icon is selected. I set that same Global Variable to “New” when the new icon was selected.
|Figure 1 – Setting Global Variable for Edit Mode|
|Figure 2 – Setting Global Variable for New Mode|
Then, I go to the screen where my Form Control is and added the following function to the “OnVisible” property:
If(varMode = “Edit”, EditForm(NewSimpleForm),NewForm(NewSimpleForm))
|Figure 3 – If Statement to Change the Form Mode|
That’s all I needed to do to be able to use the same Form Control for both the New and Edit form.
I also made a short video which walks you through how to implement this: