Open Optional Section with VBScript

M

mdsmitty

I have a form that querys 2 data tables. The second table does not contain
any data thus the Optional Section which contains the dataFields will not
open, forcing the user to open the section manually (clicking Insert Section)
in order to enter data. I would like to have the section open on the form
automatically so the user does not have to click on the link to open the
section. Is this possible and if so, does anyone have sample code to help me
accomplish this as I am a novice at VBScript.

The XOptional value of the section is: form_data_67

Thanks
Mdsmitty
 
M

mdsmitty

I actually have 3 tables from 1 database/data source, all 3 tables have a
Person# as the "connecting field". Table 1 is used in my queryFields with an
Account# which is programmatically populated into the XML (programmer does
this). The form is set to Query OnLoad. Tables 2 (patient demographics) and
3 (data from doctor's note) are then queried. Data then can be added or
updated by the user and submitted back to the data base. All of this is
working, however if there is no data returned from Table 3 then the Optional
Section containing the dataFields for Table 3 will not display on the form.
The user will have to click "Insert" in order to fill in the data and submit
it back to the database. I have the Optional Section set to be included in
the form by default (using the sections properties dialog) but it doesn't if
there is no data returned to those fields. I have attempted the following
line of code which I have discovered here in the discussion forum but I
recieve an error message.

Line of Code:

Sub XDocument_OnLoad(eventObj)
XDocument.QueryAdapter.Query()
XDocument.View.ExecuteAction("xCollection::insert", "form_data_67")
End Sub

Error Message:

InfoPath cannot open the selected form because of an error in the form's code.
The following error occurred:

Cannot use parentheses when calling a Sub
File:script.vbs
Line:38
XDocument.View.ExecuteAction("xCollection::insert", "form_data_67")

Any help or advise will be welcomed with open arms as I have been fighting
with this form for 2 weeks now.

Thanks
Mdsmitty

Henning Krause said:
Hello,

how do you query the secondary database now? By code or do you have bound it
to something?

Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)


mdsmitty said:
I have a form that querys 2 data tables. The second table does not contain
any data thus the Optional Section which contains the dataFields will not
open, forcing the user to open the section manually (clicking Insert
Section)
in order to enter data. I would like to have the section open on the form
automatically so the user does not have to click on the link to open the
section. Is this possible and if so, does anyone have sample code to help
me
accomplish this as I am a novice at VBScript.

The XOptional value of the section is: form_data_67

Thanks
Mdsmitty
 
H

Henning Krause [MVP - Exhange]

Hello,

have you tried this?

Sub XDocument_OnLoad(eventObj)
XDocument.QueryAdapter.Query()
XDocument.View.ExecuteAction "xCollection::insert", "form_data_67"
End Sub


Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)


mdsmitty said:
I actually have 3 tables from 1 database/data source, all 3 tables have a
Person# as the "connecting field". Table 1 is used in my queryFields with
an
Account# which is programmatically populated into the XML (programmer does
this). The form is set to Query OnLoad. Tables 2 (patient demographics)
and
3 (data from doctor's note) are then queried. Data then can be added or
updated by the user and submitted back to the data base. All of this is
working, however if there is no data returned from Table 3 then the
Optional
Section containing the dataFields for Table 3 will not display on the
form.
The user will have to click "Insert" in order to fill in the data and
submit
it back to the database. I have the Optional Section set to be included
in
the form by default (using the sections properties dialog) but it doesn't
if
there is no data returned to those fields. I have attempted the following
line of code which I have discovered here in the discussion forum but I
recieve an error message.

Line of Code:

Sub XDocument_OnLoad(eventObj)
XDocument.QueryAdapter.Query()
XDocument.View.ExecuteAction("xCollection::insert", "form_data_67")
End Sub

Error Message:

InfoPath cannot open the selected form because of an error in the form's
code.
The following error occurred:

Cannot use parentheses when calling a Sub
File:script.vbs
Line:38
XDocument.View.ExecuteAction("xCollection::insert", "form_data_67")

Any help or advise will be welcomed with open arms as I have been fighting
with this form for 2 weeks now.

Thanks
Mdsmitty

Henning Krause said:
Hello,

how do you query the secondary database now? By code or do you have bound
it
to something?

Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)


mdsmitty said:
I have a form that querys 2 data tables. The second table does not
contain
any data thus the Optional Section which contains the dataFields will
not
open, forcing the user to open the section manually (clicking Insert
Section)
in order to enter data. I would like to have the section open on the
form
automatically so the user does not have to click on the link to open
the
section. Is this possible and if so, does anyone have sample code to
help
me
accomplish this as I am a novice at VBScript.

The XOptional value of the section is: form_data_67

Thanks
Mdsmitty
 
M

mdsmitty

Thanks for your help Henning but I still get an error.

Microsoft VBScript runtime error: Object required: 'XDocument.View'

This is the message once I enter the debugger but the initial message is
essentially the same.

Thanks

Henning Krause said:
Hello,

have you tried this?

Sub XDocument_OnLoad(eventObj)
XDocument.QueryAdapter.Query()
XDocument.View.ExecuteAction "xCollection::insert", "form_data_67"
End Sub


Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)


mdsmitty said:
I actually have 3 tables from 1 database/data source, all 3 tables have a
Person# as the "connecting field". Table 1 is used in my queryFields with
an
Account# which is programmatically populated into the XML (programmer does
this). The form is set to Query OnLoad. Tables 2 (patient demographics)
and
3 (data from doctor's note) are then queried. Data then can be added or
updated by the user and submitted back to the data base. All of this is
working, however if there is no data returned from Table 3 then the
Optional
Section containing the dataFields for Table 3 will not display on the
form.
The user will have to click "Insert" in order to fill in the data and
submit
it back to the database. I have the Optional Section set to be included
in
the form by default (using the sections properties dialog) but it doesn't
if
there is no data returned to those fields. I have attempted the following
line of code which I have discovered here in the discussion forum but I
recieve an error message.

Line of Code:

Sub XDocument_OnLoad(eventObj)
XDocument.QueryAdapter.Query()
XDocument.View.ExecuteAction("xCollection::insert", "form_data_67")
End Sub

Error Message:

InfoPath cannot open the selected form because of an error in the form's
code.
The following error occurred:

Cannot use parentheses when calling a Sub
File:script.vbs
Line:38
XDocument.View.ExecuteAction("xCollection::insert", "form_data_67")

Any help or advise will be welcomed with open arms as I have been fighting
with this form for 2 weeks now.

Thanks
Mdsmitty

Henning Krause said:
Hello,

how do you query the secondary database now? By code or do you have bound
it
to something?

Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)


I have a form that querys 2 data tables. The second table does not
contain
any data thus the Optional Section which contains the dataFields will
not
open, forcing the user to open the section manually (clicking Insert
Section)
in order to enter data. I would like to have the section open on the
form
automatically so the user does not have to click on the link to open
the
section. Is this possible and if so, does anyone have sample code to
help
me
accomplish this as I am a novice at VBScript.

The XOptional value of the section is: form_data_67

Thanks
Mdsmitty
 
H

Henning Krause [MVP - Exhange]

Hello,

it seems that the View object has not been initialized during the OnLoad
event. The only solution I see for your problem is to modify the primary
datasource directly: Insert the necessary elements in you datasource via the
XDocument.DOM.

Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)


mdsmitty said:
Thanks for your help Henning but I still get an error.

Microsoft VBScript runtime error: Object required: 'XDocument.View'

This is the message once I enter the debugger but the initial message is
essentially the same.

Thanks

Henning Krause said:
Hello,

have you tried this?

Sub XDocument_OnLoad(eventObj)
XDocument.QueryAdapter.Query()
XDocument.View.ExecuteAction "xCollection::insert", "form_data_67"
End Sub


Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)


mdsmitty said:
I actually have 3 tables from 1 database/data source, all 3 tables have
a
Person# as the "connecting field". Table 1 is used in my queryFields
with
an
Account# which is programmatically populated into the XML (programmer
does
this). The form is set to Query OnLoad. Tables 2 (patient
demographics)
and
3 (data from doctor's note) are then queried. Data then can be added
or
updated by the user and submitted back to the data base. All of this
is
working, however if there is no data returned from Table 3 then the
Optional
Section containing the dataFields for Table 3 will not display on the
form.
The user will have to click "Insert" in order to fill in the data and
submit
it back to the database. I have the Optional Section set to be
included
in
the form by default (using the sections properties dialog) but it
doesn't
if
there is no data returned to those fields. I have attempted the
following
line of code which I have discovered here in the discussion forum but I
recieve an error message.

Line of Code:

Sub XDocument_OnLoad(eventObj)
XDocument.QueryAdapter.Query()
XDocument.View.ExecuteAction("xCollection::insert", "form_data_67")
End Sub

Error Message:

InfoPath cannot open the selected form because of an error in the
form's
code.
The following error occurred:

Cannot use parentheses when calling a Sub
File:script.vbs
Line:38
XDocument.View.ExecuteAction("xCollection::insert", "form_data_67")

Any help or advise will be welcomed with open arms as I have been
fighting
with this form for 2 weeks now.

Thanks
Mdsmitty

:

Hello,

how do you query the secondary database now? By code or do you have
bound
it
to something?

Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)


I have a form that querys 2 data tables. The second table does not
contain
any data thus the Optional Section which contains the dataFields
will
not
open, forcing the user to open the section manually (clicking Insert
Section)
in order to enter data. I would like to have the section open on
the
form
automatically so the user does not have to click on the link to open
the
section. Is this possible and if so, does anyone have sample code
to
help
me
accomplish this as I am a novice at VBScript.

The XOptional value of the section is: form_data_67

Thanks
Mdsmitty
 
M

mdsmitty

Can you elaborate further...am I doing this is my datasource (SQL) or in my
form via Microsoft Script Editor? Is there anything after XDocument.DOM?
Sorry for all the questions but I am very new to VBScript or any form of
programming for that matter.

If you see a better way to accomplish this action, I am open to suggestions.
I don't have to use the OnLoad Event, I am just using that because I need
the section to open when the user opens the form. If there is another way to
get the same result I am more that happy to attempt it. I have been fighting
with this form for a week now and will try just about anything at this point.

Thanks
Mdsmitty

Henning Krause said:
Hello,

it seems that the View object has not been initialized during the OnLoad
event. The only solution I see for your problem is to modify the primary
datasource directly: Insert the necessary elements in you datasource via the
XDocument.DOM.

Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)


mdsmitty said:
Thanks for your help Henning but I still get an error.

Microsoft VBScript runtime error: Object required: 'XDocument.View'

This is the message once I enter the debugger but the initial message is
essentially the same.

Thanks

Henning Krause said:
Hello,

have you tried this?

Sub XDocument_OnLoad(eventObj)
XDocument.QueryAdapter.Query()
XDocument.View.ExecuteAction "xCollection::insert", "form_data_67"
End Sub


Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)


I actually have 3 tables from 1 database/data source, all 3 tables have
a
Person# as the "connecting field". Table 1 is used in my queryFields
with
an
Account# which is programmatically populated into the XML (programmer
does
this). The form is set to Query OnLoad. Tables 2 (patient
demographics)
and
3 (data from doctor's note) are then queried. Data then can be added
or
updated by the user and submitted back to the data base. All of this
is
working, however if there is no data returned from Table 3 then the
Optional
Section containing the dataFields for Table 3 will not display on the
form.
The user will have to click "Insert" in order to fill in the data and
submit
it back to the database. I have the Optional Section set to be
included
in
the form by default (using the sections properties dialog) but it
doesn't
if
there is no data returned to those fields. I have attempted the
following
line of code which I have discovered here in the discussion forum but I
recieve an error message.

Line of Code:

Sub XDocument_OnLoad(eventObj)
XDocument.QueryAdapter.Query()
XDocument.View.ExecuteAction("xCollection::insert", "form_data_67")
End Sub

Error Message:

InfoPath cannot open the selected form because of an error in the
form's
code.
The following error occurred:

Cannot use parentheses when calling a Sub
File:script.vbs
Line:38
XDocument.View.ExecuteAction("xCollection::insert", "form_data_67")

Any help or advise will be welcomed with open arms as I have been
fighting
with this form for 2 weeks now.

Thanks
Mdsmitty

:

Hello,

how do you query the secondary database now? By code or do you have
bound
it
to something?

Greetings,
Henning Krause [MVP - Exchange]
==========================
Visit my website: http://www.infinitec.de
Try my free Exchange Explorer: Mistaya
(http://www.infinitec.de/software/mistaya.aspx)


I have a form that querys 2 data tables. The second table does not
contain
any data thus the Optional Section which contains the dataFields
will
not
open, forcing the user to open the section manually (clicking Insert
Section)
in order to enter data. I would like to have the section open on
the
form
automatically so the user does not have to click on the link to open
the
section. Is this possible and if so, does anyone have sample code
to
help
me
accomplish this as I am a novice at VBScript.

The XOptional value of the section is: form_data_67

Thanks
Mdsmitty
 

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