Skip to main content

AccessTr.neT


Access' Te Class Module Oluşturma

Access' Te Class Module Oluşturma

Çözüldü #1
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.
truhi, 29-09-2009 tarihinden beri AccessTr.neT üyesidir.
Cevapla
#2
(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.
.rar db2.rar (Dosya Boyutu: 28,75 KB | İndirme Sayısı: 3)
truhi, 29-09-2009 tarihinden beri AccessTr.neT üyesidir.
Cevapla
#3
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.
Cevapla
#4
(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.
truhi, 29-09-2009 tarihinden beri AccessTr.neT üyesidir.
Cevapla
#5
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.
.zip Class TextBox renk.zip (Dosya Boyutu: 99,69 KB | İndirme Sayısı: 3)
Cevapla
#6
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

.zip class alternatif(Textbox yada digerlerinin degistirildiginde olayi).zip (Dosya Boyutu: 42,36 KB | İndirme Sayısı: 3)
Cevapla

Bir hesap oluşturun veya yorum yapmak için giriş yapın

Yorum yapmak için üye olmanız gerekiyor

ya da