473,325 Members | 2,771 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,325 software developers and data experts.

Instanciate a Form from a database Field

I'm working on a simple workflow system. I need to show a form when the workflow step needs user input. The form name is stored in
a database table. Is there a way to do this? I can't seem to find the right combination.

--
Al Reid
Nov 23 '05 #1
4 1340
"Al Reid" <ar*****@reidDASHhome.com> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
I'm working on a simple workflow system. I need to show a form when the workflow step needs user input. The form
name is stored in
a database table. Is there a way to do this? I can't seem to find the right combination.

--
Al Reid


Public Sub ShowDialogByName(ByRef FormName As String)
Dim f As Windows.Forms.Form
Select Case FormName
Case "Form1"
f = New Form1
Case "Form2"
f = New Form2
Case Else
f = Nothing
End Select
If Not f Is Nothing Then
f.ShowDialog()
End If
End Sub
Nov 23 '05 #2
Thanks, but there has to be a better way and I'm sure there is. I believe
that one has to use reflection, but I haven't quite figures it out. I guess
I'll spend a little more time refining my Google search.

--
Al Reid

"Micky" <mi***@n05pam.com> wrote in message
news:dl**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
"Al Reid" <ar*****@reidDASHhome.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I'm working on a simple workflow system. I need to show a form when the
workflow step needs user input. The form name is stored in
a database table. Is there a way to do this? I can't seem to find the
right combination.

--
Al Reid


Public Sub ShowDialogByName(ByRef FormName As String)
Dim f As Windows.Forms.Form
Select Case FormName
Case "Form1"
f = New Form1
Case "Form2"
f = New Form2
Case Else
f = Nothing
End Select
If Not f Is Nothing Then
f.ShowDialog()
End If
End Sub

Nov 23 '05 #3
Dear Al Reid,

I am not sure if I understand what you mean, but if I do then I would
recommend doing the following:
Create a hashtable with the key being the a string with the form name and
the value the form object. You should limit
form creation to the object containing this hashtable in order to have all
of your forms contained by the hashtable (if this is wanted, that is).

Hope I helped you,

Michel van den Berg

"Al Reid" <ar*****@reidDASHhome.com> schreef in bericht
news:%2****************@tk2msftngp13.phx.gbl...
I'm working on a simple workflow system. I need to show a form when the
workflow step needs user input. The form name is stored in
a database table. Is there a way to do this? I can't seem to find the
right combination.

--
Al Reid

Nov 23 '05 #4
Thanks. Essentially what I was after was a way to show a form from a string containing the name of the form.

After refining my Google search I came across a way to do it using Reflection that seems to be simple and efficient AND it works.
Here is what I found:

Imports System
Imports System.Windows.Forms
Imports System.Reflection

Public Class ObjectFinder
Public Shared Function CreateObjectInstance(ByVal objectName As String) As Object
' Creates and returns an instance of any object in the assembly by its type name.

Dim obj As Object

Try
If objectName.LastIndexOf(".") = -1 Then
'Appends the root namespace if not specified.
objectName = [Assembly].GetEntryAssembly.GetName.Name & "." & objectName
End If

obj = [Assembly].GetEntryAssembly.CreateInstance(objectName)

Catch ex As Exception
obj = Nothing
End Try
Return obj

End Function

Public Shared Function CreateForm(ByVal formName As String) As Form
' Return the instance of the form by specifying its name.
Return DirectCast(CreateObjectInstance(formName), Form)
End Function

End Class

Again, it's not my code, but it works and does exactly what I was looking for.
--
Al Reid

"Michel van den Berg" <mv*@promontis.nl> wrote in message news:Oh**************@TK2MSFTNGP11.phx.gbl...
Dear Al Reid,

I am not sure if I understand what you mean, but if I do then I would
recommend doing the following:
Create a hashtable with the key being the a string with the form name and
the value the form object. You should limit
form creation to the object containing this hashtable in order to have all
of your forms contained by the hashtable (if this is wanted, that is).

Hope I helped you,

Michel van den Berg

"Al Reid" <ar*****@reidDASHhome.com> schreef in bericht
news:%2****************@tk2msftngp13.phx.gbl...
I'm working on a simple workflow system. I need to show a form when the
workflow step needs user input. The form name is stored in
a database table. Is there a way to do this? I can't seem to find the
right combination.

--
Al Reid


Nov 23 '05 #5

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

Similar topics

2
by: JJ | last post by:
Hi All, When someone selects a value in a select on a form I want to show the same form with another select with certain values depending on first select. How can I do this? Should I keep...
4
by: Andy Hutchings | last post by:
Hi everybody - hope you can help out here. I have a form in a database, which is a columnar form from one of the tables in the db - there is a sub-form to the form which is a datasheet view of...
15
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
10
by: motessa | last post by:
Hello All, I am new to Access and have been looking for answers to my problem on the internet and have not found it yet. I hope someone can give me a hint. Thanks so much. I have a form...
4
by: Steven | last post by:
Hi, I have a database table field to store the form name, I want to create the particular windows form by using the value that read from that DB field. For examples, the table field has a value...
7
by: Dan | last post by:
(Using Classic ASP & MS Access) I have a page that has 120 fields on it (mostly checkboxes). I cannot split this into smaller pages. So what i want to do is write a class that handles this. in...
17
by: Timothy.Rybak | last post by:
Hello all, This is my first attempt at an application, so kid gloves are appreciated. I need to make a very simple form that only has a few elements. One is TraceCode - a text field that is...
4
by: rszebras | last post by:
I inherited a database (as a novice at Access) and need to modify it to make it more efficient, i.e., the assignment form needs to autopopulate with the client's name, address, phone number, etc.,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.