Open a form using a variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James White

    #1

    Open a form using a variable

    I wish to open a form using a variable derived from a table. The Application is based on the switchboard principle from Access. However in the absence of do.cmd openForm, I have to use this code.
    There has to be a better way to instantiate a form surely.

    Select Case strArgument.ToU pper
    Case "frmDeptMapping sEdit".ToUpper
    Dim aa As frmDeptMappings Edit = New frmDeptMappings Edit
    open_form(aa)
    Case "frmDeptMapping stable".ToUpper
    Dim aa As frmDeptMappings Table = New frmDeptMappings Table
    open_form(aa)
    ....





    Private Sub open_form(ByVal frmToOpen As Form)

    Try
    frmToOpen.Top = 10
    frmToOpen.Left = 10
    frmToOpen.Owner = Me
    frmToOpen.Show( )
    Catch ex As Exception
    MsgBox(ex.Messa ge)
    End Try

    End Sub

  • Herfried K. Wagner [MVP]

    #2
    Re: Open a form using a variable

    "James White" <jimbo1199@noem ail.nospam> schrieb:[color=blue][color=green][color=darkred]
    >>>I wish to open a form using a variable derived from a table. The
    >>>Applicatio n is based on the switchboard principle from Access. However in
    >>>the absence of do.cmd openForm, I have to use this code.[/color][/color][/color]
    There has to be a better way to instantiate a form surely.

    Select Case strArgument.ToU pper
    Case "frmDeptMapping sEdit".ToUpper
    Dim aa As frmDeptMappings Edit = New frmDeptMappings Edit
    open_form(aa)
    Case "frmDeptMapping stable".ToUpper <<<

    \\\
    Imports System.Reflecti on
    ..
    ..
    ..
    Dim frm As Form = _
    DirectCast( _
    Activator.Creat eInstance( _
    Type.GetType("M yApplication.Sa mpleForm") _
    ), _
    Form _
    )
    frm.Show()
    ///

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • James White

      #3
      Re: Open a form using a variable

      Thanks

      I eventually used the Root Namespace as "MyApplication" , and it worked. I
      cannot find how to get the root namespace programatically , so I hard coded
      it for now.
      it is worth noting that character case of the form and namespace are
      important.

      Dim strTemp As String = "Talons2005 ." & strFormName

      Dim frmToOpen As Form = Activator.Creat eInstance(Type. GetType(strTemp ))

      frmToOpen = DirectCast(frmT oOpen, Form)

      frmToOpen.Top = 10

      frmToOpen.Left = 10

      frmToOpen.Owner = Me

      frmToOpen.Show( )

      many Thanks
      --
      James White
      CSH Consultants
      MEL/AU




      "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
      news:uW7oOIzdFH A.1448@TK2MSFTN GP14.phx.gbl...[color=blue]
      > "James White" <jimbo1199@noem ail.nospam> schrieb:[color=green][color=darkred]
      >>>>I wish to open a form using a variable derived from a table. The
      >>>>Applicati on is based on the switchboard principle from Access. However
      >>>>in the absence of do.cmd openForm, I have to use this code.[/color][/color]
      > There has to be a better way to instantiate a form surely.
      >
      > Select Case strArgument.ToU pper
      > Case "frmDeptMapping sEdit".ToUpper
      > Dim aa As frmDeptMappings Edit = New frmDeptMappings Edit
      > open_form(aa)
      > Case "frmDeptMapping stable".ToUpper <<<
      >
      > \\\
      > Imports System.Reflecti on
      > .
      > .
      > .
      > Dim frm As Form = _
      > DirectCast( _
      > Activator.Creat eInstance( _
      > Type.GetType("M yApplication.Sa mpleForm") _
      > ), _
      > Form _
      > )
      > frm.Show()
      > ///
      >
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://classicvb.org/petition/>[/color]


      Comment

      • Peter Huang [MSFT]

        #4
        Re: Open a form using a variable

        Hi

        We need the type instance to get the namespace.
        e.g.
        MsgBox(Me.GetTy pe().Namespace)

        If you have any concern, please feel free to post here.

        Best regards,

        Peter Huang
        Microsoft Online Partner Support

        Get Secure! - www.microsoft.com/security
        This posting is provided "AS IS" with no warranties, and confers no rights.

        Comment

        • Armin Zingler

          #5
          Re: Open a form using a variable

          ""Peter Huang" [MSFT]" <v-phuang@online.m icrosoft.com> schrieb[color=blue]
          > Hi
          >
          > We need the type instance to get the namespace.
          > e.g.
          > MsgBox(Me.GetTy pe().Namespace)
          >
          > If you have any concern, please feel free to post here.[/color]


          VB 2005 code? Namespace is not a property in Framework 1.1.

          As one doesn't have to specify a root namespace, it might be empty. The root
          namespace is only a simplification used by the compiler, but concerning the
          assemblies and reflection (and maybe the CLS in general; I don't know), I
          don't think there is a "root namespace" at all.


          Armin

          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Open a form using a variable

            "Armin Zingler" <az.nospam@free net.de> schrieb:[color=blue][color=green]
            >> We need the type instance to get the namespace.
            >> e.g.
            >> MsgBox(Me.GetTy pe().Namespace)
            >>
            >> If you have any concern, please feel free to post here.[/color]
            >
            > VB 2005 code? Namespace is not a property in Framework 1.1.[/color]

            Sure, it is a property of the 'Type' class even in .NET 1.1.

            --
            M S Herfried K. Wagner
            M V P <URL:http://dotnet.mvps.org/>
            V B <URL:http://classicvb.org/petition/>

            Comment

            • Armin Zingler

              #7
              Re: Open a form using a variable

              "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb[color=blue]
              > "Armin Zingler" <az.nospam@free net.de> schrieb:[color=green][color=darkred]
              > > > We need the type instance to get the namespace.
              > > > e.g.
              > > > MsgBox(Me.GetTy pe().Namespace)
              > > >
              > > > If you have any concern, please feel free to post here.[/color]
              > >
              > > VB 2005 code? Namespace is not a property in Framework 1.1.[/color]
              >
              > Sure, it is a property of the 'Type' class even in .NET 1.1.[/color]

              Arghh... was pressing "N" in the object browser - but it's there in the
              escaped version: "[Namespace]". Don't know why this was introduced at all in
              the object browser. Not necessary, I think. Only necessary in the source
              code.

              ..... Argh again ;-) This is also the reason why "GetType" wasn't found while
              writing this reply...

              Armin

              Comment

              Working...