sorun
For Each con In .Controls
If Not scr.exists(con.Name) Then DeleteControl frm.Name, con.Name
Next
kodundan kaynaklanıyor. nesne silindiğinde atlayarak dolaşıyor nesneler arasında denemelerimde bir çift nesneleri atlayıp tek nesneleri sildi
kodu aşağıdaki gibi düzenleyip dener misiniz?
Public Function butonYap()
Dim db As dao.Database
Dim rs As dao.Recordset
Dim sqlStr As String
Dim frm As Form
Dim yeni As Control
Dim i As Integer, say As Integer, ii As Integer
Dim silinmemesiGerekenler
Dim scr As Object
Dim toop As Integer
Dim scrSil() As String
Set scr = CreateObject("Scripting.Dictionary")
silinmemesiGerekenler = Array("btn1", "btn2")
DoCmd.OpenForm "Form1", acDesign
Set frm = Forms("Form1")
sqlStr = "SELECT * FROM Tablo1"
Set db = CurrentDb
Set rs = db.OpenRecordset(sqlStr)
'' On Error Resume Next
With Forms("Form1")
For i = LBound(silinmemesiGerekenler) To UBound(silinmemesiGerekenler)
scr.Add silinmemesiGerekenler(i), ""
Next
x = 0
For Each con In .Controls
If Not scr.exists(con.Name) Then
ReDim Preserve scrSil(x)
scrSil(x) = con.Name
x = x + 1
End If
Next
For x = LBound(scrSil) To UBound(scrSil)
DeleteControl frm.Name, scrSil(x)
Next x
End With
' On Error GoTo 0
'''' Err.Clear
rs.MoveFirst
say = 1
Do Until rs.EOF
If scr.exists(rs(0).Value) Then
toop = 500 + 700 * ((say - 0.6) \ 4)
Set yeni = CreateControl(frm.Name, acCommandButton, Left:=iLft, Top:=toop)
yeni.Caption = rs!aa
yeni.Name = "Button" & say
yeni.Height = 500
Set yeni = Nothing
iLft = 13 + 2085 * (say Mod 4)
say = say + 1
End If
rs.MoveNext
Loop
DoCmd.OpenForm "Form1", acNormal
Forms("Form1").Form.Requery
Set yeni = Nothing
Set frm = Nothing
Set scr = Nothing
End Function