Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Forms On The Fly 2

Status
Not open for further replies.

MissyEd

IS-IT--Management
Feb 14, 2000
303
GB
Hi all

I am interested in creating forms on the fly. At the moment, I am bouncing off ideas on how to create a form and all its controls in code, then imbue the controls with events and edit their properties.

Any ideas, please reply and we can chat about it.

Thanks Missy Ed
Looking to exchange ideas and tips on VB and MS Access development as well as office 97 development. Drop me a line: msedbbw@hotmail.com
 
Hi MissyEd,
I'd guess you like to write lots of code! Everything required to do this exists in Access. I'm not understanding your desire to do so...perhaps you would elaborate a little. X-) Gord
ghubbell@total.net
 
..................................................................................
Missy Ed,

Have you got any answer?
After I read your lines I...

Well:

I created a database (why? because it was amusing (-: ) with a table
Created a table with two field: "ID" - autonumber, and "StrDate" - String
I filled up that with "yyyy\/mm\/dd" formated text.

I have a Module1:
Public Function ChildFormOnclick()
'MsgBox Application.Forms(Application.Forms.Count - 1).Caption
DoCmd.Close acForm, Application.Forms(Application.Forms.Count - 1).Name, acSaveNo
End Function

And I have a form, with a CommandButton. The commandButton's onclick sub:
Private Sub Command0_Click()
' Dim rst As Recordset, dbs As Database
Dim frmForm1 As Form
Dim btnCmdButton As New CommandButton
Dim TxtField1, TxtField2 As New TextBox
Set frmForm1 = CreateForm

With frmForm1 'set form
.Width = 10000
.Caption = "Dinamic Form1"
.RecordSource = "Select * FROM MyTable"
.NavigationButtons = False
.Width = 5
.AllowEdits = True
.DividingLines = False
.Section(0).Height = 1100
.AutoCenter = True
.AutoResize = True
.DefaultView = 1 'Continous form

End With

Set btnCmdButton = CreateControl(frmForm1.Name, acCommandButton, acDetail, , , 100, 150, 2000, 500)

With btnCmdButton 'set close button
.OnClick = "=ChildFormOnclick()"
.Caption = "Close form"
.FontSize = 12
.FontBold = True
End With

Set TxtField1 = CreateControl(frmForm1.Name, acTextBox, acDetail, , , 100, 750, 1000, 300)

With TxtField1
.ControlSource = "ID"
End With

Set TxtField2 = CreateControl(frmForm1.Name, acTextBox, acDetail, , , 1200, 750, 1500, 300)

With TxtField2
.ControlSource = "StrDate"
End With

DoCmd.OpenForm frmForm1.Name
End Sub

Creates a form, a "close button" on it, and two textfield:
one for the "ID", one for the "StrDate"
The form is continuous form.

But:
i don't know, how to set the form header (for the command button)
If you have any ideas or example pls. write it down here, or an e-mail:
ide@innocent.com
ide s-)
 
Hi guys

The reason I'm looking into creating forms on the fly is because the company I work for is growing rapidly and the business rules change as we grow. I hoped to be able to specify rules and build a form on the fly for them. Here's an example. We process a lot of information, and these happen in steps. Say for instance, before we can accept work, we require a minimum amount of information from our clients. At the moment, if this information is not provided, we telephone and get it. But in 2 weeks time, we want to add an extra step in the process. This new step requires us to add the case to the system, then go through a number of checks to find the most efficient means of contact e.g tel, fax, letter depending on the quality of our contact information. This requires a major job on the current system. We need to write a new form, link it all in etc.

With a flexible system, I hoped to simply add entries into a number of tables and the step could be included without any extra forms being built. This could work, as most of the forms at the moment look very similar with mostly minor differences. Another example, the form to collect customer information when creating a customer account, is almost the same as the one to collect supplier information etc.

Am I spouting or is something like this possible. My difficulty is with the events really. I can set them to a public function and thats about it. Has anyone developed something similar, maybe with classes or even created wizards ? Im looking for speed and efficiency as well.

Thanks all Missy Ed
Looking to exchange ideas and tips on VB and MS Access development as well as office 97 development. Drop me a line: msedbbw@hotmail.com
 
Creating a form is the easiest part of the challenge. As you know, you can use the AutoForm button on the toolbar to create a new form based on a selected table. To automate that process, try this:

(1) Create a new blank form.
(2) Add a combo box (Combo0).
(3) Copy/paste the following as Combo0's RowSource:

SELECT MSysObjects.Name
FROM MSysObjects
WHERE (((MSysObjects.Type)=1) AND ((Left([Name],4))<>&quot;MSys&quot;))
ORDER BY MSysObjects.Name;

(4) Copy/paste the following to Combo0's AfterUpdate event:

'select form source
DoCmd.SelectObject acTable, Me!Combo0, True

'create autoform
DoCmd.RunCommand acCmdNewObjectAutoForm


(5) Switch to form view. When you select a table from Combo0, a new columnar form will be created based on the table you selected.


As far as creating functions, we'd need more info as to what it is you want to do.
 
Hi guys

The light bulb has finally gone on over my head :) I've discovered that creating the controls on the fly wouldnt work cos my form is being opened as a class. So here is what I did:

Created a form and set up all the methods & properties. Also a list of every control I would use in any situation - roughly 12 textboxes, 6 labels, 2 comboboxes, 2 command buttons and a list box. Set these all to Visible = False in design mode.

Created a table called tblControls, with fields for each stage of the operation, each step of the stage, the control name, the property to set and the setting.

Created a method on the form to loop through the table, setting whatever setting the property had listed for it in the table.

My table ended up v.long, but now all i have to do to add an extra property is add a record to the table and launch the form. For events, I created private functions on the form which used a case statement to determine what to do next e.g perform an action say, display the contents of the statusbartext in a textbox or refer to a class outside the form.

Its been working quite well. I've managed to create an entire application including error handling in just under 7 days. This is a re-write of an application which took about 1 month to code initially!

Im now having a well deserved holsten pils :) Missy Ed
Looking to exchange ideas and tips on VB and MS Access development as well as office 97 development. Drop me a line: msedbbw@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top