کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی
کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

کلینیک فوق تخصصی اکسس ( کاربرد vba در اکسس )

به اشتراک گذاری اطلاعات کسب شده در اکسس از سایت آفیس و سایت های تخصصی خارجی

ساخت کلاس ماژول


ایجاد 5 Label در فرم : 

Private click1 As New ClickLabel
Private click2 As New ClickLabel
Private click3 As New ClickLabel
Private click4 As New ClickLabel
Private click5 As New ClickLabel
Private Sub Form_Load()
Set click1.ClickLabel = Me.Label0
Set click2.ClickLabel = Me.Label1
Set click3.ClickLabel = Me.Label2
Set click4.ClickLabel = Me.Label3
Set click5.ClickLabel = Me.Label4
End Sub


کلاس ماژول به نام ClickLabel



Private withEvents mlabel as Access.Label

Public Property Get ClickLabel() As Access.Label
  Set ClickLabel = mLabel End Property Public Property Set ClickLabel(ByVal lblClickLabel As Access.Label)   Set mLabel = lblClickLabel   mLabel.OnClick = "[Event Procedure]"   mLabel.OnMouseUp = "[Event Procedure]"  End Property Private Sub mLabel_Click()   'run code here   MsgBox "You clicked label " & mLabel.Name   If mLabel.ForeColor = vbRed Then     mLabel.ForeColor = vbGreen   Else     mLabel.ForeColor = vbRed   End If End Sub Private Sub mLabel_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)   MsgBox "You moused up from " & mLabel.Name & "It is associated with record" & mRecordID End Sub



عملکردش چییست؟  بعد از ایجاد 5  لیبل در فرم  زمانیکه روی لیبل کلیک کنید پیغامی حاوی نام لیبل را به شما نمایش داده و رنگ آن تغییر میکند البته   mRecordID در کدهای بالا اعمال نشده که می توان آنرا هم ساخت و برای هر لیبل ID ساخت.



Set click5.ClickLabel = Me.Label4
click5.RecordID = 5


یک متغیر بنام mRecordID با دیتا تایپ Long تعریف کرده
از Property Get برای گرفتن رویه پراپرتی ( RecordID )  استفاده کرده و از نوع لانگ 

the Property Get statement to define a property procedure that gets the value of a property

و سپس از Property Let استفاده نموده برای تخصیص مقداردر mRecordID 

the Property Let statement to define a procedure that assigns a value to a property

Private mRecordID As Long
Public Property Get RecordID() As Long 

RecordID = mRecordID

End Property 

Public Property Let RecordID(ByVal lngRecordID As Long)
mRecordID = lngRecordID
End Property



you can only use a Property Let procedure on the left side of a property assignment expression or Let statement.


Private mstrPropertyName As String

Property Get PropertyName() As String
    PropertyName = mstrPropertyName
End Property

' You would use Let because String is a value data type
Property Let PropertyName(rData As String)
    mstrPropertyName = rData
End Property

IMPORTANT : 

The Set statement is used to make a reference of an object to an object variable. You don't have to use the Set keyword, if you are dealing with primitive and native built-in types such as integer, double, string and so on. 




The syntax of Property Set is parallel to the Property Let procedure. The only difference is that the argument is an object data type, and the VBA Set keyword is used for the assignment within the body of the Property Set. The following is an example of hypothetical Property Set procedure that accepts a recordset object and assigns it to a private variable named m_ Products:


PROPERTY SET همراستای PROPERTY LET است و تنها فرقی که دارد این است که دیتا تایپ آرگومان OBJECT است.

Public Property Set Products(Value As ADO.Recordset)
  If Not Value Is Nothing Then
    Set m_Products = Value
  End If
End Property