InfoPath 2003 VBScript capture user name and populate field issue - InfoPath Dev
in

InfoPath Dev

InfoPath 2003 VBScript capture user name and populate field issue

Last post 09-21-2011 04:39 AM by Wheels. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 06-11-2009 08:38 AM

    InfoPath 2003 VBScript capture user name and populate field issue

    Good morning all.

    I created a little test project to capture a user name in VBScript. It all works well, but when I pasted the code in the "big" project, the user name will not populate the User Name field(s).

    Has anyone out there experienced this phenomenon?

    My code is a follows:

    <code>

    Public Sub UserName()

    Dim objNet

    On Error Resume Next 'In case we fail to create object then display our custom error

    Set objNet = CreateObject("WScript.NetWork")

    Dim strInfo strInfo = objNet.UserName

    XDocument.DOM.selectSingleNode("dfs:myFields/my:LANUserID").Text = strInfo 

    XDocument.DOM.selectSingleNode("dfs:myFields/my:TestLANID").Text = strInfo 

    Set objNet = Nothing 'Destroy the Object to free the Memory

    End Sub

    </code>

     Any ideas?

     Thank you, WHEELS

  • 06-11-2009 02:12 PM In reply to

    Re: InfoPath 2003 VBScript capture user name and populate field issue

    Hi Wheels,

    Well, are you calling the new subroutine? Since I can't see the rest of your code, I have no way of debugging it. Just adding this routine won't result in it working since something has to call it.

    Patrick Halstead
    Project Manager at Qdabra
  • 06-12-2009 04:42 AM In reply to

    Re: InfoPath 2003 VBScript capture user name and populate field issue

    Hi Patrick.

    I had this code in the form laod event:

    Sub XDocument_OnLoad(eventObj)
    'line 20
    Dim objNet
    On Error Resume Next 'In case we fail to create object then display our custom error
    Set objNet = CreateObject("WScript.NetWork")
     
    Dim strInfo
    strInfo = objNet.UserName
    XDocument.DOM.selectSingleNode("dfs:myFields/my:LANUserID").Text = strInfo
    'XDocument.UI.Alert(strInfo)
    XDocument.DOM.selectSingleNode("dfs:myFields/my:TestLANID").Text = XDocument.DOM.selectSingleNode("dfs:myFields/my:LANUserID").Text
    'strInfo = "User Name is     " & objNet.UserName & vbCRLF & _
              '"Computer Name is " & objNet.ComputerName & vbCRLF & _
             ' "Domain Name is   " & objNet.UserDomain
    'MsgBox strInfo

    Set objNet = Nothing                    'Destroy the Object to free the Memory

    End Sub

     but now I call it from the form laod as follows:

    Sub XDocument_OnLoad(eventObj)

    UserName
    End Sub

  • 09-19-2011 07:41 AM In reply to

    • stara
    • Top 200 Contributor
    • Joined on 10-20-2010
    • Posts 54

    Re: InfoPath 2003 VBScript capture user name and populate field issue

    Hi,

     Were you able to resolve this issue? Beacuse I'm trying to do the same and it doesn't work after the form is published. I have it in the on_load event. It works well when I try in the design to Preview form mode. I would like to capture user name once the form is submitted.

    Thanks,

    Stara 

     

  • 09-19-2011 10:15 AM In reply to

    Re: InfoPath 2003 VBScript capture user name and populate field issue

    Hi Stara.

    I was able to resolve this issue, and haven't worked on it for years (doesn't seem that long ago).

    I'm not entirely sure what you are trying to do, but I'll give it my best shot:

    My code is as follows:

    Sub XDocument_OnLoad(eventObj)

    Dim objNet On Error Resume Next 'In case we fail to create object then display our custom error

    Set objNet = CreateObject("WScript.NetWork") Dim strInfo Dim userName2 XDocument.DisplayAlerts = False

    strInfo = objNet.UserName XDocument.DOM.selectSingleNode("dfs:myFields/my:LANUserID").Text = strInfo

    End Sub

    I derived the user name (in my company it is a code like ABCDE), and then used the variable in an SQL --> Access query to resolve the ID into a actual name. I have also done this by automating to Outlook (in other  (VBA) projects). I'm sure you could tie the Function to run off the submit button on your form.

    WHEELS

  • 09-20-2011 11:48 AM In reply to

    • stara
    • Top 200 Contributor
    • Joined on 10-20-2010
    • Posts 54

    Re: InfoPath 2003 VBScript capture user name and populate field issue

    Were you able to get the user name after the form was published? It works for me only in the Preview, but nothing happens when form is published.

     

    Let me know.

     

    Thanks

  • 09-21-2011 04:39 AM In reply to

    Re: InfoPath 2003 VBScript capture user name and populate field issue

    I don't particually care for InfoPath or Access to much. I do C#.NET, SQL Server, and Teradata these days. It is really difficult to recall what I did two years ago, but I recall something about setting the form as Fully Trusted. I hope that helps.

     I found the following post relating to a Trusted form and user name: http://social.msdn.microsoft.com/Forums/en-US/sharepointinfopath/thread/705c108d-e945-46bb-80d5-ece8106dada8.

    WHEELS

Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.