Open existing form calling it from a texbox in vb2008

C

Cosimo

hi. my progect contain about 100 forms. i would call them runtime, giving
it's name in a texbox. (fox example: i write "DATA" in textbox and programm
open form that have the same name)
of course, i can use select case/ case = "DATA"/ data.show().
But, 100 forms are too much. There's a more dinamic solution to retrieve the
form by a string like texbox.text? thanks!!
 
T

Tieske

I don't think I understand exactly what it is you are trying to do, but why
not create an extra form, which contains just a listbox. During the form_open
event you populate the listbox with the names of all the forms in your
database.
In the doubleclick event you then add code to open the selected form

wouldn't that be easier than typing the names manually?
 
C

Cosimo

Thanks for answer,
well, in this program i have a lot of forms. All forms are easly
client-accessible by a main menù in the start form (a tree view control), but
i wont to give to experts
users (that know the name of forms) a faster way to open form.
So they wont in the start form (the same of main menù) a textbox in whic
they can write directly then name of form.
If you know SAP system this way is similar to SAP-ERP ok-code method.
I tried in this way:

Dim fForm As Form = Nothing
For Each fForm In Forms
If fForm.Name = txtGoForm.Text Then
fcode = fForm
End If
Next
fcode.MdiParent = Me
fcode.Show()

but with vb.net i must declare all forms.

'declare forms
Forms.Add(form1)
Forms.Add(form2)
etc..etc..

i wouldn't declare all forms in my project manually. There's another system?
Thanks again
(and sorry for my english)
 
T

Tieske

if your textbox is named "MyTextBox" then this should work

Private Sub MyTextBox_AfterUpdate()
On Error Resume Next
DoCmd.OpenForm MyTextBox.Value
If Not IsLoaded(MyTextBox.Value) Then
MsgBox "There is no form by that name"
End If
End Sub

Public Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet view.
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top