web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to write the code ...
Power Apps
Answered

How to write the code to change the FormMode from View to New when a LookUp function does not find a match?

(0) ShareShare
ReportReport
Posted on by 115

I have created a gallery that when I go to the "Detail Form" it will allow me to see data in another forms as well. The Detail screen contains:

DetailForm1 - Gallery1 is the source for this form

Form2 -Event Data is the source for this form

Each form contains the same data field called Title. 

 

I have used a LookUp function in Items of Form2 to pull data from its source if the data matches the data field from the Gallery textbox referred to as DataCardValue1If their is data already in the Event Data source matching then Form2's mode is 'View'. I would like to change the mode to 'New' so I can add data to the file from Gallery1 on Form2 if it hasn't already been added. 

 

The code I have written is the following:

If(LookUp('Event Data', DataCardValue1.Text = Title, Title), FormMode.View, If(!IsBlank(LookUp('Event Data', DataCardValue1.Text = Title, Title)), FormMode.New, FormMode.View), FormMode.New, FormMode.View).

 

I see a message that there is an error in the formula, describing it as there was an expected value compatible with 'DataSource'. I am not sure how to fix this error. Any suggestions?

 

Ange

 

 

Categories:
I have the same question (0)
  • asdasdasdasdasd Profile Picture
    72 on at

    Just a thought,

    Your if statement condition is, LookUp('Event Data', DataCardValue1.Text = Title, Title), which should return true or false. 

    You could wrap it in !IsBlank(LookUp('Event Data', DataCardValue1.Text = Title, Title)) and that will return true if data exists

  • Verified answer
    CU22081303-0 Profile Picture
    150 on at

    This might work for you. I can't test this exact formula since I don't have those tables, but I made it work with a similar code and just swapped out my tables for yours.

    This goes in the "DefaultMode" property of the Form if I understand correctly.

    If(IsBlank(LookUp('Event Data', DataCardValue1.Text = Title,Title)),
    FormMode.New,
    FormMode.Edit
    )

     

     

  • Sawh Profile Picture
    115 on at

    I tried that but it didn't work.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,033

#2
Valantis Profile Picture

Valantis 632

#3
11manish Profile Picture

11manish 607

Last 30 days Overall leaderboard