How To Use A DataSource From VB Code

M

Marion

I have a web service that supplies me with the next available number each
time I ask for it. However, I have that datasource as "Automatically retrieve
data when form is opened", so I am burning through number way to fast. What I
want to do is assign a default value to my FormID field of "<NEW>" and then
in the OnLoad event do something like this:

Sub XDocument_OnLoad(evetnObj)
if XDocument.DOM.selectSingleNode("//my:FormID").text = "<NEW>" then
XDocument.DOM.selectSingleNode("//my:FormID").text =
XDocument.DataAdapters("NewNumber").Value
end if
End Sub

So can someone supply me with the correct code to do this, please?
 
S

S.Y.M. Wong-A-Ton

You don't need to write code for this, but if you really want to there is a
Query method on the DataAdapter (see
http://msdn.microsoft.com/en-us/library/bb229804.aspx) you can use to execute
your data connection.

What I would suggest is removing the "Automatically retrieve data when form
is opened" check box. You can then add a rule to your form for when the form
opens (Tools > Form Options > Open and Save > Rules) with an Action to "Query
using a data connection" the data connection for your web service. Then in
the Rule dialog box, you can click "Set Condition" to add a condition for
this rule. The Condition must check the value of the FormID field, and if it
is equal to "<NEW>" run the rule. Then you can use another rule to set the
FormID field to the value returned by your web service.
 

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