D
Dan
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)
' Write your code that will run before a Save or Save As
operation here.
Dim flname As String
flname =
MainDataSource.CreateNavigator().SelectSingleNode("/myFields/dataFields/TimeTable/ID").ToString
Me.SetSaveAsDialogFilename(flname)
Me.SetSaveAsDialogLocation("g:\!workgrp\tenures\tenuretracking\savedforms")
' The Dirty property will be set to false if save is successful.
e.PerformSaveOperation()
' Write your code that will run after saving here.
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?
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)
' Write your code that will run before a Save or Save As
operation here.
Dim flname As String
flname =
MainDataSource.CreateNavigator().SelectSingleNode("/myFields/dataFields/TimeTable/ID").ToString
Me.SetSaveAsDialogFilename(flname)
Me.SetSaveAsDialogLocation("g:\!workgrp\tenures\tenuretracking\savedforms")
' The Dirty property will be set to false if save is successful.
e.PerformSaveOperation()
' Write your code that will run after saving here.
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?