Visual Basic.net txt field - InfoPath Dev
in

InfoPath Dev

Visual Basic.net txt field

Last post 11-02-2005 12:09 PM by franck. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 11-02-2005 08:24 AM

    Visual Basic.net txt field

    Trying to pass a string to a field on my infopath form triggered by a command button , click.

    Keep getting an error saying "Reference to undeclared namespace prefix: 'myFields'."

    Here's the code :


    <InfoPathEventHandler(MatchPath:="New", EventType:=InfoPathEventType.OnClick)> _
    Public Sub New_OnClick(ByVal e As DocActionEvent)


    Dim myField As String
    myField = "Hello World"
    e.XDocument.DOM.selectSingleNode("//myFields:GrpName").text()=myField


    End Sub


  • 11-02-2005 09:45 AM In reply to

    Re: Visual Basic.net txt field

    Hi,

    Assuming that GrpName is a string in your schema, try:
    thisXDocument.DOM.selectSingleNode("/my:myFields/my:GrpName").text = myField

    Regards,

    Franck Dauché
  • 11-02-2005 10:07 AM In reply to

    Re: Visual Basic.net txt field

    Exactly. Tried and got similar error

    System.NullReferenceException
    Object reference not set to an instance of an object.
    at InfoPathProject1.InfoPathProject1.New_OnClick(DocActionEvent e) in C:\Documents and Settings\kkaylor\My Documents\Visual Studio Projects\InfoPathProject1\FormCode.vb:line 61
    at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)


    Public Sub New_OnClick(ByVal e As DocActionEvent)
    Dim myField As String

    myField = "Hello World"
    thisXDocument.DOM.selectSingleNode("/my:myFields/my:GrpName").text = myField


    End Sub
  • 11-02-2005 10:20 AM In reply to

    Re: Visual Basic.net txt field

    Hi,

    I bet the XPath is not right. Try this first:
    Start a new blank InfoPath / VB.Net project
    Add 1 field (string), called: GrpName.
    Drop a button on your form and add that line of code:
    <InfoPathEventHandler(MatchPath:="CTRL1_5", EventType:=InfoPathEventType.OnClick)> _
    Public Sub CTRL1_5_OnClick(ByVal e As DocActionEvent)
    thisXDocument.DOM.selectSingleNode("/my:myFields/my:GrpName").text = "test"
    End Sub

    Once you you get that working, go back to your form and right click on your GrpName field in your schema:
    Go the Validation and Event Handlers Tab
    Select the OnBeforeChange Event
    Click Edit.
    The MatchPath will give you your exact XPath.
    Use that, it should help.

    Regards,

    Franck Dauché
  • 11-02-2005 10:53 AM In reply to

    Re: Visual Basic.net txt field

    That Worked! Thancks Franck
  • 11-02-2005 12:09 PM In reply to

    Re: Visual Basic.net txt field

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