cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mx
Advocate III
Advocate III

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

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
Resolver I
Resolver I

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
Advocate III
Advocate III

"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

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

@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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,647)