Hi. I went through some very informative links on namespece definitions and secondary datasources.
http://www.infopathdev.com/blogs/matt/archive/2006/02/02/Setup-Namespaces-for-a-Secondary-Data-Source.aspx
http://www.infopathdev.com/forums/p/5299/20981.aspx#20981
http://www.infopathdev.com/forums/p/10045/35640.aspx#35640
I am using Infopath 2003 SP2, Access 2003 and prg language is VBScript. I have a form where I need to access a secondary datasource named UserAccess to find the access of the user who logs in.
The secondary datasource looks like below:
myFields
dataFields
d:UserAccess
I have added the following namespacesDefinition in the form which I got in the properties of UserAccess.
XDocument.GetDOM("UserAccess").setProperty "SelectionNamespaces", "xmlns:ns1=""http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"""
The code looks like below:
Sub btn_Test_OnClick(eventObj)
dim orig_sql, criteria, new_sql, user_acc
orig_sql = XDocument.DataAdapters("UserAccess").Command
msgbox(orig_sql)
criteria = "SNS002" ' hardcoding only for testing
new_sql = orig_sql + " where userid = '" + criteria + "'"
msgbox(new_sql)
XDocument.DataAdapters("UserAccess").Command = new_sql
XDocument.DataAdapters("UserAccess").Query()
user_acc = XDocument.getDOM("UserAccess").selectSingleNode("ns1:useracc").value
msgbox(user_acc)
End Sub
The line of code where I try to access the value from useracc column throws an error 'Object required'. I have tried using:
XDocument.getDOM("UserAccess").selectSingleNode("/ns1:useracc").value
XDocument.getDOM("UserAccess").selectSingleNode("/ns1:@useracc").value and many other combinations but nothing helped.
What am I doing wrong? Is the namespacesDefinition wrong? I intend to use the same logic to check whether a user is entering duplicate data in a column which has unique key constraint.
Please help!!