Was getting current user name on form before data connection.... - InfoPath Dev
in

InfoPath Dev

Was getting current user name on form before data connection....

Last post 03-23-2009 04:49 AM by pellj. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 03-18-2009 07:43 AM

    • pellj
    • Not Ranked
    • Joined on 03-18-2009
    • Posts 2

    Was getting current user name on form before data connection....

    First off thanks for viewing my first question.

     I had a form that was not connected to a database that used the following code form http://msdn.microsoft.com/en-us/library/aa942693(VS.80).aspx to get the current username in real time so that permission to fields could be controlled by the currrent user.

    Public Sub FormEvents_Loading(ByVal sender As Object, ByVal e As LoadingEventArgs)
       Dim root, user As System.Xml.XPath.XPathNavigator
       root = Me.MainDataSource.CreateNavigator
       user = root.SelectSingleNode("/my:myFields/my:employee", Me.NamespaceManager)
       user.SetValue(System.Environment.UserName)
    End Sub

    Now I have a database that I want to use as a base for the form. Since I have created the database and need to submit and review data, I create the form from the database table.  Now when I add the code below I always get a null error on the  following line:

       user.SetValue(System.Environment.UserName)

    I noticed that on the design task/data source screen, non database form had new field "user", database connected form has "my:user".  This must be throwing off the code but I don' t see where one would alter code for this extra "my:". 

    Please advise,

    Jason

     

  • 03-21-2009 05:34 AM In reply to

    Re: Was getting current user name on form before data connection....

    Hi, and welcome:

    You will have to modify your code to the correct XPath for your new form:

       user = root.SelectSingleNode("/my:myFields/my:employee", Me.NamespaceManager)

    The bold section needs the XPath to the field you'd like to put the user error in. You can right click the field in the Data Source Task Pane on the form when it is in Design mode, and paste the correct XPath in the quotes. You are getting an error because the XPath doesn't point to a valid node, thus user, which you are trying to set a value on, is null.

    Hilary Stoupa

  • 03-23-2009 04:49 AM In reply to

    • pellj
    • Not Ranked
    • Joined on 03-18-2009
    • Posts 2

    Re: Was getting current user name on form before data connection....

     

    Thanks, I will definetly give it a try!!!!
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.