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

موديول: كود إضافة قيمة غير موجودة بالقائمة لمربع سرد (Not In List)


ابو جودي

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

أضف اختيارا إلى قائمة مربع التحرير والسرد عن طريق إضافة سجل إلى الجدول الخاص بمصدر الصف في حدث NotInList لمربع التحرير والسرد.

الكود داخل الموديول 

Public Sub CmboNotInList(ByVal strTableName As String, ByVal strFieldName As String, ByVal strNewData As String, ByRef intResponse As Integer)

On Error GoTo Proc_Err
   
   Dim sSQL As String
   Dim sMsg As String

   intResponse = acDataErrContinue
   
   sMsg = """" & strNewData & """ is not in the current list. " & vbCrLf & vbCrLf & "Do you want to add it? "
   
   If MsgBox(sMsg, vbYesNo, "Add New Data") <> vbYes Then
      GoTo Proc_Exit
   End If
   
   sSQL = "INSERT INTO [" & strTableName & "] " & "([" & strFieldName & "])" & " SELECT """ & strNewData & """;"
      
   With CurrentDb
      .Execute sSQL
      If .RecordsAffected > 0 Then
         intResponse = acDataErrAdded
      End If
   End With
   
Proc_Exit:
   Exit Sub
Proc_Err:
   MsgBox Err.Description, , "ERROR " & Err.Number & "   CmboNotInList"
   Resume Proc_Exit
   Resume
End Sub

يتم استدعاء الكود فى الحدث  >>------> عند عدم الوجود فى القائمة  -  NotInList  من خلال الكود الاتى 

Call CmboNotInList("tableName", "FieldName", NewData, Response)

 

المرفق 

 

Not In List.mdb

  • Like 1
رابط هذا التعليق
شارك

3 ساعات مضت, ابا جودى said:

أضف اختيارا إلى قائمة مربع التحرير والسرد عن طريق إضافة سجل إلى الجدول الخاص بمصدر الصف في حدث NotInList لمربع التحرير والسرد.

الكود داخل الموديول 


Public Sub CmboNotInList(ByVal strTableName As String, ByVal strFieldName As String, ByVal strNewData As String, ByRef intResponse As Integer)

On Error GoTo Proc_Err
   
   Dim sSQL As String
   Dim sMsg As String

   intResponse = acDataErrContinue
   
   sMsg = """" & strNewData & """ is not in the current list. " & vbCrLf & vbCrLf & "Do you want to add it? "
   
   If MsgBox(sMsg, vbYesNo, "Add New Data") <> vbYes Then
      GoTo Proc_Exit
   End If
   
   sSQL = "INSERT INTO [" & strTableName & "] " & "([" & strFieldName & "])" & " SELECT """ & strNewData & """;"
      
   With CurrentDb
      .Execute sSQL
      If .RecordsAffected > 0 Then
         intResponse = acDataErrAdded
      End If
   End With
   
Proc_Exit:
   Exit Sub
Proc_Err:
   MsgBox Err.Description, , "ERROR " & Err.Number & "   CmboNotInList"
   Resume Proc_Exit
   Resume
End Sub

يتم استدعاء الكود فى الحدث  >>------> عند عدم الوجود فى القائمة  -  NotInList  من خلال الكود الاتى 


Call CmboNotInList("tableName", "FieldName", NewData, Response)

 

المرفق 

 

Not In List.mdb 744 kB · 3 downloads

السلام عليكم استاذي الفاضل ابا جودي

انا عندي هذا الكود يعمل نفس العمل الذي قمت به بدون موديول 

سؤوالي هل يوجد فرق بين الكدين

Private Sub ww_NotInList(NewData As String, Response As Integer)
 Dim ctl As Control
   Dim strSQL As String
   Set ctl = Me!ww
   DoCmd.Beep
   If MsgBox(" القيمة النصية التي أضفتها" & " / " & _
   Me.ww.Text & " / ليس من ضمن القائمة هل تريد إضافتها الى القائمة ", _
      vbInformation, "!! ... انتباه") = vbOK Then
      
      Response = acDataErrAdded
      
      strSQL = "INSERT INTO  tbl_city(city) VALUES('"
      strSQL = strSQL & NewData & "');"
      
      CurrentDb.Execute strSQL
      DoCmd.Beep
      MsgBox "تمت إضافة القيمة الجديدة المكتوبة الى القائمة بنجاح", , "الإضافة الجديدة"
   Else
      Response = acDataErrContinue
      ctl.Undo
   End If
End Sub

 

  • Like 1
  • Haha 1
رابط هذا التعليق
شارك

لا خالص ما فى اى فرق النتيجة واحدة 

ولكن

لو كنت اريد تكرار الطريقة مع اكثر من مربع سرد

سوف تكتب كل تلك الاسطر مع كل مربع

ولكن ان كان الكود فى الموديول يكتب مرة واحدة 

ويتم فى كل مرة كتابة سطر واحد لاستدعائه 

Call CmboNotInList("tableName", "FieldName", NewData, Response)

 

وكل الطرق تؤدى الى روما :yes:

  • Like 1
رابط هذا التعليق
شارك

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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

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

Important Information