2011-05-30 55 views
0

我想在Access中創建表格200個文本框與for循環,並呼籲他們S1,S2,S3等創建動態文本框如何獲取VBA

我不希望通過創建它們我自己在形式設計。我可以有代碼示例嗎?

+1

聽起來像作業... – 2011-05-30 20:51:53

+3

你爲什麼要這樣做?這聽起來像是一個糟糕的設計,因爲任何原因,但它也是你不想在生產應用程序中做的事情。 – 2011-05-30 22:34:55

回答

5

我同意這不是一個非常好的主意,但是爲了給人們足夠的繩索來掛上.........。

Public Function Make_controls(iLoops As Integer) 
DoCmd.OpenForm "frmYour_form", acDesign 
Dim x As Integer 
Dim ctrl As Control 

For x = 1 To iLoops 
    Set ctrl = CreateControl("frmYour_form ", acTextBox, acDetail, , "", 0 + (x * 300), 0, 300, 240) 
    ctrl.ControlName = "txtDynamic_control_" & x 

    DoCmd.Save acForm, " frmYour_form " 
Next x 
DoCmd.Close acForm, " frmYour_form ", acSaveYes 

End Function