(22/03/2020, 20:07)accessman yazdı: form adını ve control adını class a argument olarak nasıl gönderebiliriz yani class form1 den ve metin13 den bağımsız olsunBirinci yöntem alttaki kodlar gibi property olarak yapılabilir.
Kod:
Public Property Get formad() As Variant
FormAdi = pFormad
End Property
Public Property Let formad(ByVal FormAdi As Variant)
pFormad = FormAdi
End Property
Kod:
olay.formad = "Form1"
Dim pFormad
For Each kontrol In Forms(pFormad)
Kod:
Option Compare Database
Private Const olayTextBox As String = "[Event Procedure]"
Private WithEvents ClassTextBox As Access.TextBox
Dim pFormad
Public Sub Initialize(TextBox As Access.TextBox)
Set ClassTextBox = TextBox
ClassTextBox.OnChange = olayTextBox
End Sub
Public Sub Terminate()
Set ClassTextBox = Nothing
End Sub
Private Sub ClassTextBox_Change()
Dim kontrol As Control
Dim aa
aa = vbNullString
For Each kontrol In Forms(pFormad)
If kontrol.ControlType = acTextBox Then
If kontrol.Tag = "xx" Then
kontrol.Application.RunCommand acCmdSave
aa = aa & "," & kontrol
End If
End If
Next
aa = Mid(aa, 2)
Forms("Form1").Controls("Metin13") = Empty
Forms("Form1").Controls("Metin13") = aa
If Len(ClassTextBox) > 0 Then
ClassTextBox.SelStart = Len(ClassTextBox)
Else
ClassTextBox.SelStart = 1
End If
If Forms("Form1").Controls("Metin13") = ",,," Then Forms("Form1").Controls("Metin13") = Empty
End Sub
Public Property Get formad() As Variant
FormAdi = pFormad
End Property
Public Property Let formad(ByVal FormAdi As Variant)
pFormad = FormAdi
End Property
Kod:
Private Sub Form_Load()
Dim olay As New ClassTextboxSec
Dim kontrol As Access.Control
Set olay = New ClassTextboxSec
olay.formad = "Form1"
Set KontrolCollection = New Collection
For Each kontrol In Me.Controls
If kontrol.ControlType = acTextBox Then
If kontrol.Tag = "xx" Then
Set olay = New ClassTextboxSec
olay.Initialize kontrol
KontrolCollection.Add olay, kontrol.name
End If
End If
Next
Set olay = Nothing
Set Control = Nothing
End Sub