473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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.ToUpper
Case "frmDeptMappingsEdit".ToUpper
Dim aa As frmDeptMappingsEdit = New frmDeptMappingsEdit
open_form(aa)
Case "frmDeptMappingstable".ToUpper
Dim aa As frmDeptMappingsTable = New frmDeptMappingsTable
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.Message)
End Try

End Sub

Nov 21 '05 #1
6 2478
"James White" <ji*******@noemail.nospam> schrieb:
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.ToUpper
Case "frmDeptMappingsEdit".ToUpper
Dim aa As frmDeptMappingsEdit = New frmDeptMappingsEdit
open_form(aa)
Case "frmDeptMappingstable".ToUpper<<<

\\\
Imports System.Reflection
..
..
..
Dim frm As Form = _
DirectCast( _
Activator.CreateInstance( _
Type.GetType("MyApplication.SampleForm") _
), _
Form _
)
frm.Show()
///

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

Nov 21 '05 #2
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.CreateInstance(Type.GetType(strTemp))

frmToOpen = DirectCast(frmToOpen, Form)

frmToOpen.Top = 10

frmToOpen.Left = 10

frmToOpen.Owner = Me

frmToOpen.Show()

many Thanks
--
James White
CSH Consultants
MEL/AU


"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uW**************@TK2MSFTNGP14.phx.gbl...
"James White" <ji*******@noemail.nospam> schrieb:
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.ToUpper
Case "frmDeptMappingsEdit".ToUpper
Dim aa As frmDeptMappingsEdit = New frmDeptMappingsEdit
open_form(aa)
Case "frmDeptMappingstable".ToUpper<<<

\\\
Imports System.Reflection
.
.
.
Dim frm As Form = _
DirectCast( _
Activator.CreateInstance( _
Type.GetType("MyApplication.SampleForm") _
), _
Form _
)
frm.Show()
///

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

Nov 21 '05 #3
Hi

We need the type instance to get the namespace.
e.g.
MsgBox(Me.GetType().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.

Nov 21 '05 #4
""Peter Huang" [MSFT]" <v-******@online.microsoft.com> schrieb
Hi

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

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

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

Nov 21 '05 #5
"Armin Zingler" <az*******@freenet.de> schrieb:
We need the type instance to get the namespace.
e.g.
MsgBox(Me.GetType().Namespace)

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


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


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/>
Nov 21 '05 #6
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
"Armin Zingler" <az*******@freenet.de> schrieb:
We need the type instance to get the namespace.
e.g.
MsgBox(Me.GetType().Namespace)

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


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


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


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

Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Raptor | last post by:
I'm a complete Javascript n00b, using a snippet I found on the web. I'll probably be buying a Javascript book. What's the authoritative on-line resource for Javascript, like php.net is for PHP? ...
1
by: Konstantin | last post by:
Can someone help me figure out a way to open a form only once in an MDI app. I have an MDI app that contains several forms. I use each form depending on the type of document that the user needs...
55
by: Steve Jorgensen | last post by:
In a recent thread, RKC (correctly, I believe), took issue with my use of multiple parameters in a Property Let procedure to pass dimensional arguments on the basis that, although it works, it's...
4
by: Corepaul | last post by:
I am working in Windows 2000 and Access 2000 and am a rookie in Access. Coding merrily along, I stop periodically to test that everything works. After adding a small amount of code to several...
13
by: Seth Spearman | last post by:
Hey guys, I have the following code: '****************************************************** If Not Me.NewRecord Then Dim rs As DAO.Recordset Dim strBookmark As String Set rs =...
15
by: Dave | last post by:
Has anyone encountered the error message "Can not open any more databases" and what did you do to solve it? Thanks, Dave
7
by: Steve_Black | last post by:
Hello, I'm toying with the idea of loading a MenuStrip (VB.Net 2005) dynamically based on who is logged into my system. Every user has different security settings and I want to customize the...
2
by: Jim M | last post by:
I rarely deal with recordsets directly with code, since I usually use Access queries, so be patient with this question. I want to open a recordset with various default variables used by my program....
7
by: martin DH | last post by:
Hello, I have a report that I open that pull its data from a form that builds a where string. Opening the report first opens the form, where I enter criteria, and then pulls matching records from a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.