tags:

views:

58

answers:

2

Hi,Please Help me in following problem: this code work in VB but doesn't work in VBA:

also I add in beginning a combobox with index 0 to form1

For i = 1 To 5
  Load Combo1(i)
  Combo1(i).Visible = True
  Combo1(i).Left = Combo1(i - 1).Left + Combo1(0).Width
Next i

I will have this code in VBA. thank you

A: 

I think the index property is not available in VBA; I am not sure how it works in VB though.

Nilesh Deshmukh
+1  A: 

Are you thinking of something on the lines of:

Sub AddControls()
Dim frm As Form
Dim iTop, iWidth, iHeight, iLeft

DoCmd.OpenForm "FormNameHere", acDesign
Set frm = Forms!FormNameHere

iTop = 100
iWidth = 1500
iHeight = 300
iLeft = 100

For i = 1 To 5
  Set ctl = CreateControl(frm.Name, acComboBox, , , , iLeft, iTop, iWidth, iHeight)
  ctl.Visible = True
  ctl.Name = "Combo1" & i
  iLeft = ctl.Left + ctl.Width
Next i

DoCmd.Restore
End Sub
Remou