AccessTr.neT

Tam Versiyon: Access' Te Class Module Oluşturma
Şu anda arşiv modunu görüntülemektesiniz. Tam versiyonu görüntülemek için buraya tıklayınız.
Sayfalar: 1 2
Merhaba,

Formda 20 tane metin kutusu mevcut, bu metin kutusununa tıkladığımız zaman aşağıdaki kodun çalışması için;
her bir metin kutusuna kod yazmadan Excel' de olduğu gibi class oluşturarak çözebilir miyiz?


Kod:
Private Sub m1_1_Enter()

If m1_1.BackColor = -2147483643 Then
    m1_1.BackColor = 0
ElseIf m1_1.BackColor = 0 Then
    m1_1.BackColor = -2147483643
End If

End Sub

teşekkürler,
iyi Çalışmalar.
(17/07/2023, 17:17)truhi yazdı: [ -> ]Merhaba,

Formda 20 tane metin kutusu mevcut, bu metin kutusununa tıkladığımız zaman aşağıdaki kodun çalışması için;
her bir metin kutusuna kod yazmadan Excel' de olduğu gibi class oluşturarak çözebilir miyiz?


Kod:
Private Sub m1_1_Enter()

If m1_1.BackColor = -2147483643 Then
    m1_1.BackColor = 0
ElseIf m1_1.BackColor = 0 Then
    m1_1.BackColor = -2147483643
End If

End Sub

teşekkürler,
iyi Çalışmalar.

Merhaba,
Class oluşturmayla ilgili ekli dosyadaki bir kod buldum ama;

teşekkürler, iyi çalışmalar.
Bir module ekleyin ve aşağıdaki kodu ekleyin
Kod:
Option Compare Database
Option Explicit

Dim WithEvents txtBoxes As Access.Forms.Controls

Private Sub Form_Load()
    Set txtBoxes = Me.Controls
End Sub

Private Sub txtBoxes_Enter(Index As Integer)
    Dim currentTextBox As Control
    Set currentTextBox = Me.Controls(txtBoxes(Index).Name)
    
    If currentTextBox.BackColor = -2147483643 Then
        currentTextBox.BackColor = 0
    ElseIf currentTextBox.BackColor = 0 Then
        currentTextBox.BackColor = -2147483643
    End If
End Sub
bu kod form yüklenirken textbox kontrollerini tanımlayıp herbirinin Enter olayını izleryecektir. Herhangi bir textbox tıklandığında da txtBoxes_Enter olayı tetiklenecek ve arka plan rengini değiştirecektir.
(19/07/2023, 08:30)atoykan yazdı: [ -> ]Bir module ekleyin ve aşağıdaki kodu ekleyin
Kod:
Option Compare Database
Option Explicit

Dim WithEvents txtBoxes As Access.Forms.Controls

Private Sub Form_Load()
    Set txtBoxes = Me.Controls
End Sub

Private Sub txtBoxes_Enter(Index As Integer)
    Dim currentTextBox As Control
    Set currentTextBox = Me.Controls(txtBoxes(Index).Name)
    
    If currentTextBox.BackColor = -2147483643 Then
        currentTextBox.BackColor = 0
    ElseIf currentTextBox.BackColor = 0 Then
        currentTextBox.BackColor = -2147483643
    End If
End Sub
bu kod form yüklenirken textbox kontrollerini tanımlayıp herbirinin Enter olayını izleryecektir. Herhangi bir textbox tıklandığında da txtBoxes_Enter olayı tetiklenecek ve arka plan rengini değiştirecektir.

Hocam teşekkürler,
buradaki kodlar formun içine mi yazılacak? yoksa eklenecek bir modül içine yazılacak,

sanırsam bu kodun form' un kendine modülüne yazılması gerekecek?
Kod:
Private Sub Form_Load()
    Set txtBoxes = Me.Controls
End Sub
iyi Çalışmalar.
Bende kodlar çalışmadığı için size arşivimden bir örnek atım.

[Event Procedure] olarak beraber kullanılıyor galiba class ile ama excelde bu yoktu.
Buda class sız alternatif arşivden.


Kod:
Option Compare Database

Private Sub Form_Load()

    Dim ctl As Control
    
    For Each ctl In Me.Controls
        Select Case ctl.ControlType
            Case acTextBox, acComboBox 'TextBox ve ComboBox icin
                If ctl.Tag = "degistiginde" Then
                    ctl.OnChange = "=Degisti([" & ctl.Name & "])"
                    ctl.OnGotFocus = "=ArdRenk([" & ctl.Name & "])"
                    ctl.OnLostFocus = "=ArdRenkCik([" & ctl.Name & "])"
                End If
            Case acCommandButton 'CommandButton ve TextBox ve ComboBox icin
                If ctl.Tag = "degistiginde" Then
                    ctl.OnGotFocus = "=ArdRenk([" & ctl.Name & "])"
                    ctl.OnLostFocus = "=ArdRenkCik([" & ctl.Name & "])"
                End If

        End Select
    Next ctl

End Sub

Public Function Degisti(ctl As Control) 'TextBox ve ComboBox icin
    Me.Metin0 = ctl.Text
End Function

Public Function ArdRenk(ctl As Control) 'TextBox ve ComboBox ve CommandButton icin
    ctl.BackColor = vbGreen
End Function

Public Function ArdRenkCik(ctl As Control) 'TextBox ve ComboBox ve CommandButton icin
    ctl.BackColor = vbWhite
End Function
Sayfalar: 1 2