Sub
BuildForm_New(strSource As
String)
Dim frm As Form, ctl As Control
Dim db As
DAO.Database, fld As DAO.Field, obj As Object
Dim tdf As
DAO.TableDef, qdf As DAO.QueryDef
Dim intType As Integer
Dim intLeft As Integer, intWidth As Integer, intHeight As
Integer, intTop As
Integer
'
intLeft = 0: intTop = 0: intHeight = 240
'
Set db = CurrentDb
' added
On Error Resume Next
Set tdf = db.TableDefs(strSource)
If Err.Number = 0 Then
Set obj = db.TableDefs(strSource)
Else
Err.Clear
Set obj = db.QueryDefs(strSource)
If Err.Number <> 0 Then
Set obj = db.CreateQueryDef("",
strSource)
End If
End If
Set tdf = Nothing
Set qdf = Nothing
'
Set frm = CreateForm
With frm
.RecordSource = strSource
.DefaultView = 1
.Section(acDetail).Height = intHeight
DoCmd.RunCommand acCmdFormHdrFtr
.Section(acHeader).Visible = True
.Section(acHeader).Height = intHeight
.Section(acFooter).Height = 0
For Each fld In obj.Fields
Select Case fld.Type
Case dbByte, dbInteger, dbLong, dbSingle, dbDouble,
dbCurrency, dbDecimal, dbFloat, dbNumeric
intType = acTextBox
intWidth = 1440
Case dbText, dbMemo
intType = acTextBox
intWidth = 1440
Case dbDate
intType = acTextBox
intWidth = 1440
Case dbBoolean
intType = acCheckBox
intWidth = 260
Case Else
intType = acTextBox
intWidth = 1440
End Select
'
Set ctl = CreateControl(frm.NAME,
intType, acDetail, , , intLeft, intTop, intWidth)
With ctl
.ControlSource = fld.NAME
.NAME = fld.NAME
.SpecialEffect = 0
.BorderStyle = 1
If intType <> acCheckBox Then
.FontName = "Arial"
.FontSize = 8
End If
End With
'
Set ctl = CreateControl(frm.NAME,
acLabel, acHeader, , , intLeft, intTop, intWidth, intHeight)
With ctl
.Caption = fld.NAME
.FontName = "Arial"
.FontSize = 8
End With
'
intLeft =
intLeft + intWidth
Next fld
End With
End Sub