Hi I'm new to blogs/forums and InfoPath! I'm struggling with what is probably a very simple piece of vbscript on a button on an InfoPath form which selects a number from a seconday data source (Access database table). The number it selects is the highest number in those which could be chosen, I need it to be the lowest! If you could help I would most grateful. The exsiting vbscript code is below, with the area where I believe the problem to be is now BOLD.
Sub CTRL401_4_OnClick(eventObj)
' Code for 'Start Number Allocation Process'
'VARIABLES
'SITEID used to differentiate between sites without naming issues
Dim strSITE
Dim strSITEID
Dim strNEWNUM
Dim strNAME
Dim strEXISTS
Dim strNONSTD
'Dim strALERT
strEXISTS=1
'INFOPATH READ INFO from Non-Standard table
strSITE = Xdocument.dom.selectSingleNode("//dfs:myFields/dfs:dataFields/d:Non-Standard_Table/@SiteName").text
strSITEID = Xdocument.dom.selectSingleNode("//dfs:myFields/dfs:dataFields/d:Non-Standard_Table/@SiteID").text
strNAME = Xdocument.dom.selectSingleNode("//dfs:myFields/dfs:dataFields/d:Non-Standard_Table/@GeneralName").text
strNONSTD = Xdocument.dom.selectSingleNode("//dfs:myFields/dfs:dataFields/d:Non-Standard_Table/@NonStdReq").text
'strALERT = XDocument.UI.Alert("Numbers for IPT equipment cannot be allocated from the Non-Standard range. Please use the correct form.")
' open database
set db = CreateObject("ADODB.Connection")
db.Open("Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\PaDa\InfoPath Test Area\Databases\Non-Standard.mdb")
'Non-Standard required?
If strNONSTD = "Yes" then
' use SQL to select information from Available table in Non-Standard.mdb
sql = "select * from Available"
set rs = db.Execute(sql)
' read resulting record set
do until rs.EOF
if rs("Allocated") = "OPEN" and rs("Site") = strSITE then
strNEWNUM = rs("Number")
end if
if rs("Allocated") = strSITE then
strEXISTS = rs("Number")
end if
rs.MoveNext
loop
'Set Existing Number Reservation
if strEXISTS <> 1 then
strNEWNUM = strEXISTS 'e.g. If strEXISTS is changed from 1 to 10 strNEWNUM will be 10
end if
' use SQL to insert new data into Available table in Non-Standard.mdb
sql = "UPDATE Available SET Allocated = ('"& strNAME & "') WHERE Number = ('"& strNEWNUM & "')"
set rs = db.Execute(sql)
'WRITE TO INFOPATH
Xdocument.dom.selectSingleNode("//dfs:myFields/dfs:dataFields/d:Non-Standard_Table/@AllocatedNumber").text=strNEWNUM
end if
End Sub