اذهب الي المحتوي
أوفيسنا
بحث مخصص من جوجل فى أوفيسنا
Custom Search

مطلوب كود يعطي اسم الحقل الحالى


ledoledo

الردود الموصى بها

وعليكم السلام :rol:

 

وبعد إذن أخي ابوخليل :rol:

 

هنا اجمع جميع الطرق اللي تخطر على بالي ، وهي 4 طرق:rol:

 

1. طريقة أخي ابوخليل:

280.Clipboard01.jpg.2ce6855dd72affd0746c


Private Sub Text0_Click()

    Me.Text0 = Me.Text0.Name
End Sub

.

الطرق الثلاث الباقية تعتمد على الوحدة النمطية:

Option Compare Database

Function Who_Am_I()

    Dim frm As Access.Form
    Dim ctl As Access.Control
     
    Set frm = Screen.ActiveForm         'get the active Form Name
    Set ctl = Screen.ActiveControl      'get the active Control (in our case it was a field) name
    
    'The way we address a Field in another Form,
    'like this: Forms!FormName!FieldName
    'so we have to do it here similarly,
    'this will send the field name to the active Field in the active Form
    Forms(frm.Name)(ctl.Name) = ctl.Name
    
    'this will return the Funtion Who_Am_I value to the variable that called it
    Who_Am_I = ctl.Name
    
End Function

2. ننادي الوحدة النمطية مباشرة (لاحظ علامة =  ) ، ولا يوجد كود محلي في VBA :

280.Clipboard02.jpg.e09ed6a6e7b6e2237525

.

3. نعمل كود محلي ، والذي ينادي الوحدة النمطية:


Private Sub Text4_Click()

    'this way will get the field name from the Function Who_Am_I
    'and it will place the value in the Field in the Form
    Call Who_Am_I
    
    'this way will get the field name from the Function Who_Am_I
    'and it will place the value in the Field in the Form
    'and it WILL place the Field name in the variable A, so that we can use it
    A = Who_Am_I
    MsgBox A
    
End Sub

280.Clipboard03.jpg.3ba219ea59f643ed96cc

.

وبما اننا نادينا الوحدة النمطية Who_Am_I عن طريق المتغير A ،

فاصبح المتغير A لديه نتيجة/قيمة الوحدة النمطية ، 

وعليه نستطيع ان نستخدم هذه القيمة كيف نشاء في الكود ،

فمثلا استخدمناها لإعطاءنا رسالة بإسم الحقل ،

والنتيجة:

280.Clipboard03.1.jpg.cb13c65fbed8597d1d

.

4. نعمل ماكرو ، ونجعل الماكرو ينادي الوحدة النمطية:

280.Clipboard05.jpg.cd5004aadff5a9c11ad3

.

(لاحظ مافي علامة =  ) ، ولا يوجد كود محلي في VBA:

280.Clipboard04.jpg.4a034ca1189b9721eaa6

.

 

جعفر

280.db2016.accdb.zip

تم تعديل بواسطه jjafferr
إضافة لكود الوحدة النمطية ، وكود الحقل Text4
  • Like 4
رابط هذا التعليق
شارك

من فضلك سجل دخول لتتمكن من التعليق

ستتمكن من اضافه تعليقات بعد التسجيل



سجل دخولك الان
  • تصفح هذا الموضوع مؤخراً   0 اعضاء متواجدين الان

    • لايوجد اعضاء مسجلون يتصفحون هذه الصفحه
×
×
  • اضف...

Important Information