Custom save function with code - InfoPath Dev
in

InfoPath Dev

Custom save function with code

Last post 03-02-2010 04:33 PM by dc330. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 03-02-2010 01:44 PM

    • dc330
    • Not Ranked
    • Joined on 12-03-2009
    • Posts 23

    Custom save function with code

    Hello, I want to add custom code (VB) to my Access database connected form which will generate a filename and path when the user clicks Save.
    I've added the following code to the save behaviour but I'm having trouble figuring out the syntax to pull data out of fields on the form.
    This is my code:

    Public Sub FormEvents_Save(ByVal sender As Object, ByVal e As SaveEventArgs)
        Dim flname As String
        flname = MainDataSource.CreateNavigator().SelectSingleNode("/myFields/dataFields/TimeTable/ID").ToString
        Me.SetSaveAsDialogFilename(flname)
        Me.SetSaveAsDialogLocation("g:\!workgrp\tenures\tenuretracking\savedforms")
        e.PerformSaveOperation()
        e.CancelableArgs.Cancel = False
    End Sub

    This is the error I get: (It works if I comment out the flname = statement.)

    System.NullReferenceException Object reference not set to an instance of an object.
       at Road_Permit_Amendment.FormCode.FormEvents_Save(Object sender, SaveEventArgs e)
       at Microsoft.Office.InfoPath.Internal.FormEventsHost.OnSaveRequest(SaveEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnSaveRequest(SaveEvent pEvent)  

    Can someone please tell me what I'm doing wrong?

     

  • 03-02-2010 04:33 PM In reply to

    • dc330
    • Not Ranked
    • Joined on 12-03-2009
    • Posts 23

    Re: Custom save function with code

    Found the correct code for the flname = statement:

    flname = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:TimeTable/@ID", NamespaceManager).Value

    Thanks to anyone who was looking at this for me.

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