Save using custom code question - InfoPath Dev
in

InfoPath Dev

Save using custom code question

Last post 03-02-2010 04:34 PM by dc330. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 03-02-2010 08:36 AM

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

    Save using custom code question

    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

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

    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:34 PM In reply to

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

    Re: Save using custom code question

    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.