Creating forms in Access Basic

jtinker

New member
Local time
Today, 23:16
Joined
Apr 10, 2000
Messages
5
I want to create a form whose layout is based upon the values in a table. How do I create a form from scratch, using code?
 
Answering my own question:
(If someone has a better approach, I'm listening.)

Dim i As Integer

Dim jftControl As Control
Dim jftControlName As String

Dim jftDB As Database
Dim jftForm As Form
Dim jftFormName As String
Dim jftOldName As String

' Create form for display
jftFormName = "ProductDisplay"
Set jftForm = CreateForm()
jftOldName = jftForm.FormName
' Close form, to be able to rename it.
DoCmd.Close acForm, jftOldName, acSaveYes
' Delete old version of form.
On Error Resume Next
DoCmd.DeleteObject acForm, jftFormName
On Error GoTo Err_Command0_Click
DoCmd.Rename NewName:=jftFormName, ObjectType:=acForm, OldName:=jftOldName
' -----

' Modify form in design mode. Assign record source and caption.
DoCmd.OpenForm FormName:=jftFormName, View:=acDesign
Set jftForm = Forms(jftFormName)
With jftForm
.RecordSource = "Product"
.Caption = "Product Construction Display"
.DefaultView = 1 'Continuous
.Detail.Height = 400
End With
 

Users who are viewing this thread

Back
Top Bottom