Hi.
I created code which makes dynamically form with bounded controls for all columns. I show it to you below.
My problem is, how I have to change this code to create form which record source are few (e.x. 2) tables?
Thank you for help
If you want to use this code, you only have to change value of:
- nazwaTabeli (table's name of which you want to create form)
- nazwaForlumarza (form's name that you want to create)
And code:
P.S. sory for my english
I created code which makes dynamically form with bounded controls for all columns. I show it to you below.
My problem is, how I have to change this code to create form which record source are few (e.x. 2) tables?
Thank you for help
If you want to use this code, you only have to change value of:
- nazwaTabeli (table's name of which you want to create form)
- nazwaForlumarza (form's name that you want to create)
And code:
Code:
Option Compare Database Sub Formularz() Dim Formularz As form Dim ctlLabel As Control, ctlText As Control Dim polTextX As Integer, polTextY As Integer Dim polLabelX As Integer, polLabelY As Integer Dim roznicaX As Integer, roznicaY As Integer, licznik As Integer Dim nazwaTabeli As String, nazwaFormularza As String 'Ustawienia nazw tabeli i formularza nazwaTabeli = "Zamowienia_" nazwaFormularza = "Formularz" 'Check if form of table you want to create is open If CurrentProject.AllForms(nazwaFormularza).IsLoaded = False Then 'Check if form you want to create exist Dim FormularzAktualny As AccessObject For Each FormularzAktualny In Application.CurrentProject.AllForms If FormularzAktualny.Name = nazwaFormularza Then DoCmd.DeleteObject acForm, nazwaFormularza Exit For Next FormularzAktualny ' Position of new formants polLabelX = 100 polLabelY = 100 polTextX = 1000 polTextY = 100 roznicaY = 300 roznicaX = 2500 'Numer pola-1 licznik = 0 'Creation of new form Set Formularz = CreateForm Formularz.RecordSource = nazwaTabeli ' Creation of controls for all columns in table Dim bazadanych As Database Dim pola As Field Dim tabela As TableDef Set bazadanych = CurrentDb Set tabela = bazadanych.TableDefs(nazwaTabeli) For Each pola In tabela.Fields 'Textboxes Set ctlText = CreateControl(Formularz.Name, acTextBox, , "", pola.Name, _ polTextX + roznicaX, polTextY + roznicaY * licznik) 'Labels Set ctlLabel = CreateControl(Formularz.Name, acLabel, , _ ctlText.Name, pola.Name, polLabelX, polLabelY + roznicaY * licznik) licznik = licznik + 1 Next 'Set ctlText = CreateControl(frm.Name, acTextBox, , "", nazwaPola, _ 'intDataX, intDataY) ' Create child label control for text box. 'Set ctlLabel = CreateControl(frm.Name, acLabel, , _ 'ctlText.Name, nazwaLabela, intLabelX, intLabelY) ' Restore form. - niepotrzebne 'DoCmd.Restore 'Saving, closing, changing name and opening once more form that was created DoCmd.Save acForm, "Formularz1" DoCmd.Close acForm, "Formularz1", acSaveYes DoCmd.Rename nazwaFormularza, acForm, "Formularz1" DoCmd.OpenForm nazwaFormularza, , , , , acWindowNormal 'If form of a name you want to create is open how msg Else: MsgBox "Formularz jest już uruchomiony", vbOKOnly, "Uwaga" End If End Sub
Comment