Previous Button

D

Debs

I'm new to InfoPath...I have a button labelled"Previous". When the button is
pressed, I would like for it to go to the previous view.
 
S

S.Y.M. Wong-A-Ton

Have you already tried adding a rule to the button to switch between views?

- Double-click on the button to open its "Properties" dialog box.
- Click on "Rules..." button to open "Rules" dialog box.
- Click on "Add..." button on "Rules" dialog box to add a rule.
- Click on "Add Action..." button on "Rule" dialog box to add an action.
- Select "Switch views" and select view to switch to from drop-down list
boxes on "Action" dialog box.
- Click on "OK" button when closing all dialog boxes.
 
D

Debs

Thanks for answering so quickly. Sorry, I did not mention that I have 6
views. So the "Previous" button should be able to go to any of the views the
user came from.

Debs
 
S

S.Y.M. Wong-A-Ton

I'm assuming you have buttons on those 6 views that direct the user to the
view where the "Previous" button is located? If you do, you could add a field
to your Main DOM to be able to record the name of the last view visited. Add
a rule on each one of those 6 buttons that sets the value of the field to the
name of the view where each button is located. Once the user clicks on a
button, the field will be populated with the name the last view visited. You
can then retrieve this name (= the value of the field) in the OnClick event
handler of the "Previous" button and use it to programmatically switch views
using the SwitchView method (see
http://msdn.microsoft.com/library/en-us/ipsdk/html/xdmthSwitchView_HV01021422.asp?frame=true).
 
D

Debs

:
I'm not too experienced coding. I went to the link you provided, but did
not quite understand it. Can you give me an example? By the way where do you
put the code?

Thanks!

Debs
 
S

S.Y.M. Wong-A-Ton

Let's say you have two views with the names: "View 1" and "Final". On "View
1" you have a button with a rule set on it to go to view "Final" whenever the
button is clicked. On view "Final" you have your "Previous" button.

Add a field to your Main DOM via the "Data Source" pane. Let's call it
"lastViewName". Go to view "View 1" and add another rule to the button that
says:

Set a field's value: lastViewName = "View 1"

Now go to view "Final" and double-click on the "Previous" button to open its
"Properties" dialog box. Click on the "Edit Form Code..." button to add an
OnClick event handler for the button. Microsoft Script Editor will open and
the cursor will be located in the OnClick event handler for the button. Add
the following code where the cursor is located:

var lastViewName = XDocument.DOM.selectSingleNode("//my:lastViewName").text;
XDocument.View.SwitchView(lastViewName);

Note: I'm assuming that you're using JScript to program. Before you click on
the "Edit Form Code..." button on the "Properties" dialog box of the button
on the view you must make sure that your language is set correctly by
checking this via Tools > Options... > Design tab > Default programming
language.

Save your work and test it.
 
D

Debs

I'm elated! It works! Thanks so much!

Debs

S.Y.M. Wong-A-Ton said:
Let's say you have two views with the names: "View 1" and "Final". On "View
1" you have a button with a rule set on it to go to view "Final" whenever the
button is clicked. On view "Final" you have your "Previous" button.

Add a field to your Main DOM via the "Data Source" pane. Let's call it
"lastViewName". Go to view "View 1" and add another rule to the button that
says:

Set a field's value: lastViewName = "View 1"

Now go to view "Final" and double-click on the "Previous" button to open its
"Properties" dialog box. Click on the "Edit Form Code..." button to add an
OnClick event handler for the button. Microsoft Script Editor will open and
the cursor will be located in the OnClick event handler for the button. Add
the following code where the cursor is located:

var lastViewName = XDocument.DOM.selectSingleNode("//my:lastViewName").text;
XDocument.View.SwitchView(lastViewName);

Note: I'm assuming that you're using JScript to program. Before you click on
the "Edit Form Code..." button on the "Properties" dialog box of the button
on the view you must make sure that your language is set correctly by
checking this via Tools > Options... > Design tab > Default programming
language.

Save your work and test it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top