Here is situation :
Something about applivation : Application is developed for purpose of
manufacture menagment.
We are currently designing a module for check-list functionality, wich
consists of serie of properties and each of them is different data-type and
has different type of entry.
In practise , it looks like this:
PropertyName PropertyDataType
PropertyControl
WIDTH NUMBER TEXTBOX
HEIGHT NUMBER TEXTBOX
LENGHT NUMBER TEXTBOX
CHIPBOARD_DECOR TEXT COMBOBOX
CHIPBOARD_THICKNES NUMBER COMBOBOX
In real situation we have from 30 to 100 properties per product.
Idea is to enable design department to define properies and list of values
(for combobox properties) for each of product entity.
Different set of key properties is for wardrobe, table , laboratory table,
office closet.
So when sales personal create demand towards manufacturing department, they
must fill check-list to define each of key properties for product entity.
What is my problem?
I have to dynamically define a form depending on product entity user
selected, and i have achive it , but it must be compatible with MDE
deployment.
My solution is based on 'CreateForm' and 'CreateControl' functions, works
great ,each time i generate frmSubForm and display it throught SubForm
control.
Back few years, when I developed in VB6 i had comfort to dinamically create
controls from code using load function (if my memory works), in access i can
achive it only in design view using 'CreateControl' function.
Is there alternative ?
I have another idea, but I would like to avoide playing with visible
property.
Here is my code:
<CODE START>
On Error Resume Next
SubStavke.SourceObject = "frmProdajaPLIzradaSubPrazno"
DoCmd.DeleteObject acForm, "frmProdajaPLIzradaSub"
Dim frmTmp As Form
'Podesi svojstva forme u ovoj fazi
Set frmTmp = CreateForm
frmTmp.Section(acDetail).BackColor = Me.Section(acDetail).BackColor
Dim rstGrupe As DAO.Recordset
Dim ctlLabels() As Label
Dim ctlCombos() As ComboBox
Dim ctlTexts() As TextBox
Dim ctlLines() As Line
Dim lngLabelsCount As Long
Dim lngCombosCount As Long
Dim lngTextsCount As Long
Dim lngLinesCount As Long
Dim lngRazmak As Long 'Izmeðu kontrola!
Dim lngVertikalnoStanje As Long
Dim lngGrupeXOffset As Long
Dim lngSvojstvaXOffset As Long
Dim lngSvojstvaNazivWidth As Long
'Postavi uvlaku po x-u
lngGrupeXOffset = 500
lngSvojstvaXOffset = 500
'Postavi dimenzije
lngSvojstvaNazivWidth = 2500
'Vertikalni razmak izmeðu kontrola!
lngRazmak = 100
Dim strSvojstvaGrupe As String
strSvojstvaGrupe = "SELECT ProdajaPLSvojstvaGrupe_INT.SGrupaRb,
ProdajaPLSvojstvaGrupe_INT.SGrupaNaziv ,SGrupaId " & _
"FROM ProdajaPLSvojstvaGrupe_INT " & _
"GROUP BY ProdajaPLSvojstvaGrupe_INT.SGrupaRb,
ProdajaPLSvojstvaGrupe_INT.SGrupaNaziv,SGrupaId " & _
"ORDER BY ProdajaPLSvojstvaGrupe_INT.SGrupaRb;"
Set rstGrupe = CurrentDb.OpenRecordset(strSvojstvaGrupe, dbOpenSnapshot)
'Odma n a prvu grupu u listi
rstGrupe.MoveFirst
'Sve kreiraj pod generiranim imenom tipa "From1"
While Not rstGrupe.EOF = True
ReDim Preserve ctlLabels(lngLabelsCount)
ReDim Preserve ctlLines(lngLinesCount)
'Kreiraj kapcije za grupe svojstava
Set ctlLabels(lngLabelsCount) = CreateControl(frmTmp.Name, acLabel,
acDetail, , , lngGrupeXOffset, lngVertikalnoStanje, 1000, 300)
Set ctlLines(lngLinesCount) = CreateControl(frmTmp.Name, acLine,
acDetail, , , lngGrupeXOffset, lngVertikalnoStanje, 1000, 300)
'Svojstva labela!
ctlLabels(lngLabelsCount).Caption = rstGrupe!SGrupaNaziv
ctlLabels(lngLabelsCount).FontName = "Arial CE"
ctlLabels(lngLabelsCount).FontSize = 9
ctlLabels(lngLabelsCount).ForeColor = 16776960
ctlLabels(lngLabelsCount).FontBold = 800
ctlLabels(lngLabelsCount).SizeToFit
'Linija
ctlLines(lngLinesCount).Top = ctlLabels(lngLabelsCount).Top +
ctlLabels(lngLabelsCount).Height
ctlLines(lngLinesCount).Left = ctlLabels(lngLabelsCount).Left
ctlLines(lngLinesCount).Width = 5000
ctlLines(lngLinesCount).Height = 0
ctlLines(lngLinesCount).SpecialEffect = 2
'Pomakni brojaèe!
lngVertikalnoStanje = lngVertikalnoStanje + lngRazmak +
ctlLabels(lngLabelsCount).Height
lngLabelsCount = lngLabelsCount + 1
lngLinesCount = lngLinesCount + 1
'Pobroji svojstva za grupu sortirano po rb unosa!
Dim strSvojstvaZaGrupu As String
Dim rstSvojstvaZaGrupu As DAO.Recordset
strSvojstvaZaGrupu = "SELECT * FROM ProdajaPLSvojstva_INT WHERE
SvojstvoGrupaId=" & rstGrupe!SGrupaId & " ORDER BY SvojstvoRb"
Set rstSvojstvaZaGrupu = CurrentDb.OpenRecordset(strSvojstvaZaGrupu,
dbOpenSnapshot)
'Træi na prvi!
rstSvojstvaZaGrupu.MoveFirst
While Not rstSvojstvaZaGrupu.EOF = True
'NASLOVI SVOJSTAVA
'Prvo label zatim kontrola za unos!
ReDim Preserve ctlLabels(lngLabelsCount)
'Kreiraj kapcije za grupe svojstava
Set ctlLabels(lngLabelsCount) =
CreateControl(frmTmp.Name, acLabel, acDetail, , , lngSvojstvaXOffset,
lngVertikalnoStanje, lngSvojstvaNazivWidth, 300)
'Svojstva labela!
ctlLabels(lngLabelsCount).Caption =
rstSvojstvaZaGrupu!SvojstvoNaziv & " :"
ctlLabels(lngLabelsCount).FontName = "Arial CE"
ctlLabels(lngLabelsCount).FontSize = 9
ctlLabels(lngLabelsCount).ForeColor = RGB(255,
255, 255)
ctlLabels(lngLabelsCount).FontBold = 400
'ctlLabels(lngLabelsCount).SizeToFit
ctlLabels(lngLabelsCount).TextAlign = 3 'Right
'Pomakni brojaèe!
lngLabelsCount = lngLabelsCount + 1
'Kontrole za unos Select case
Select Case
(rstSvojstvaZaGrupu!SvojstvoUnosVrsta)
Case "UNOS"
'Textboxovi!
ReDim Preserve ctlTexts(lngTextsCount)
Set ctlTexts(lngTextsCount) =
CreateControl(frmTmp.Name, acTextBox, acDetail, , , lngSvojstvaXOffset,
lngVertikalnoStanje, 1500, 300)
ctlTexts(lngTextsCount).Left =
ctlLabels(lngLabelsCount - 1).Left + ctlLabels(lngLabelsCount - 1).Width +
50
ctlTexts(lngTextsCount).Width = 1500
ctlTexts(lngTextsCount).FontName =
"Courier New CE"
ctlTexts(lngTextsCount).FontSize = 9
ctlTexts(lngTextsCount).Name =
rstSvojstvaZaGrupu!SvojstvoNaziv
Select Case
(rstSvojstvaZaGrupu!SvojstvoTip)
Case "BROJ"
ctlTexts(lngTextsCount).DefaultValue
= 0
ctlTexts(lngTextsCount).Format =
"Standard"
Case "TEKST"
ctlTexts(lngTextsCount).DefaultValue
= ""
ctlTexts(lngTextsCount).Format =
""
End Select
lngTextsCount = lngTextsCount + 1
Case "LISTA"
'Textboxovi!
ReDim Preserve ctlCombos(lngCombosCount)
Set ctlCombos(lngCombosCount) =
CreateControl(frmTmp.Name, acComboBox, acDetail, , , lngSvojstvaXOffset,
lngVertikalnoStanje, 2000, 300)
ctlCombos(lngCombosCount).Left =
ctlLabels(lngLabelsCount - 1).Left + ctlLabels(lngLabelsCount - 1).Width +
50
ctlCombos(lngCombosCount).Width = 2000
ctlCombos(lngCombosCount).FontName =
"Courier New CE"
ctlCombos(lngCombosCount).FontSize = 9
ctlCombos(lngCombosCount).Name =
rstSvojstvaZaGrupu!SvojstvoNaziv
ctlCombos(lngCombosCount).RowSourceType
= "Table/Query"
ctlCombos(lngCombosCount).RowSource =
"SELECT Vrijednost FROM ProdajaPLSvojstvaListe_INT " & _
"WHERE
SvojstvoId=" & rstSvojstvaZaGrupu!SvojstvoId & " " & _
"ORDER
BY ItemId"
ctlCombos(lngCombosCount).LimitToList =
True
lngCombosCount = lngCombosCount + 1
End Select
'---------------------------------------------------------------------------------------------------------
lngVertikalnoStanje = lngVertikalnoStanje + lngRazmak +
ctlLabels(lngLabelsCount - 1).Height
rstSvojstvaZaGrupu.MoveNext
Wend
'----------------------------------------------------------------------
rstGrupe.MoveNext
Wend
'Finalne korekcije!
frmTmp.Section(acDetail).Height = frmTmp.Section(acDetail).Height + 200
frmTmp.DividingLines = False
frmTmp.NavigationButtons = False
frmTmp.RecordSelectors = False
frmTmp.ScrollBars = 2
Dim strFrmTmpName As String
strFrmTmpName = frmTmp.Name
DoCmd.Save acForm, frmTmp.Name
DoCmd.Close acForm, frmTmp.Name, acSaveYes
DoCmd.Rename "frmProdajaPLIzradaSub", acForm, strFrmTmpName
<CODE END>