Hi Zekebark and welcome to our forum!
Here's an excerpt from Chapter 2 of my book. Note: this does not use the InfoPath 2007 object model.
Imports System
Imports Microsoft.Office.Interop.InfoPath.SemiTrust
Imports Microsoft.VisualBasic
' Office integration attribute. Identifies the startup class for the form. Do not
' modify.
<Assembly: System.ComponentModel.DescriptionAttribute("InfoPathStartupClass, Version=1.0, Class=Hello_World.Hello_World ")>
Namespace Hello_World
' The namespace prefixes defined in this attribute must remain synchronized with
' those in the form definition file (.xsf).
<InfoPathNamespace("xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-02-07T05-55-01'")> _
Public Class Hello_World
Private thisXDocument As XDocument
Private thisApplication As Application
Public Sub _Startup (app As Application, doc As XDocument)
thisXDocument = doc
thisApplication = app
' You can add additional initialization code here.
End Sub
Public Sub _Shutdown ()
End Sub
End Class
End Namespace