cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mx
Level 8

How to Disable DELETE button on an Edit Form when adding new record ?

I have the following:

Gallery with Add button (+)

Edit Form with the following buttons:

Cancel (X),

Delete (name is IconDelete1_1 on EditScreen1)

Save

On the Gallery, when I click the Add button to add a new record, how can I disable the Delete button on the Edit Form ?

 

This is of course to prevent the user from attempting to Delete a non-existent record (SQL Server back end). From what I can tell, you need to use UpdateContext() and so on.

I've tried multiple different syntax's and so on, but to no avail.
DatabaseMX ('mx')
Microsoft Access MVP
1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: How to Disable DELETE button on an Edit Form when adding new record ?

Hi @mx

 

Select your Delete button and change its Display Mode property to:

 

If(
    Form1.Mode = FormMode.Edit,
    DisplayMode.Edit,
    DisplayMode.Disabled
)

Form1 is the name of your form

View solution in original post

4 REPLIES 4
Venxir
Level: Powered On

Re: How to Disable DELETE button on an Edit Form when adding new record ?

I assume that your Add button will invoke a NewForm(<FormName>)?

 

Then you should use the formmode of your Edit Form.

 

Just disable the delete button when Form.Mode = FormMode.New, If you edit an existing record the mode will be Edit and when vieweing a record the mode will be View.

mx
Level 8

Re: How to Disable DELETE button on an Edit Form when adding new record ?

"I assume that your Add button will invoke a NewForm()?"

Correct.

Then you should use the formmode of your Edit Form."

"Just disable the delete button when Form.Mode = FormMode.New,"

 

Sooo ... how do I do that ? What is the code/syntax to actuallyDisable the DELETE button ... and where would I put it?

Is there an event when the Edit Form opens ? thx

DatabaseMX ('mx')
Microsoft Access MVP
Anonymous
Not applicable

Re: How to Disable DELETE button on an Edit Form when adding new record ?

Hi @mx

 

Select your Delete button and change its Display Mode property to:

 

If(
    Form1.Mode = FormMode.Edit,
    DisplayMode.Edit,
    DisplayMode.Disabled
)

Form1 is the name of your form

View solution in original post

Highlighted
mx
Level 8

Re: How to Disable DELETE button on an Edit Form when adding new record ?

@Martynas
OK ... that works. Thank you.

Note:
This is what was in the Delete button DisplayMode property:

 

If(!IsBlank(BrowseGallery1.Selected) && DataSourceInfo('[NEM].[ztblNEM2Enh]', DataSourceInfo.DeletePermission), DisplayMode.Edit, DisplayMode.Disabled)

 

where [NEM].[ztblNEM2Enh] is a table in my SQL Server back end.


It would seem that code (generated when I let PA create the app) should Disable the button, but it's not. I think that is because there is always an item 'selected' in the BrowseGallery1.

 

I tried just If(!IsBlank(BrowseGallery1.Selected), DisplayMode.Edit, DisplayMode.Disabled) ... that does not work either.
Why do you suppose that is ?

 

Nonetheless ... I'm using the code you provided. I'm not really concerned with 'DeletePermission' in this app.

Appreciate the help.

 

Funny ... I've been working 24x7x365 with Microsoft Access / VBA for 25 years. Things like this are second nature. BUT ... the syntax in PA is quite different. BOOM !

DatabaseMX ('mx')
Microsoft Access MVP

Helpful resources

Announcements
thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Kudoed Authors (Last 30 Days)
Users online (4,471)