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

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

قام بنشر (معدل)

السلام عليكم اخوتي الكرام

محتاج مثال لكود vba لإنشاء جدول وتحديد نوع الحقول ( رقم - نص - تاريخ -) وخاصة الحقل من النوع yes/no

جزاكم الله كل خير

تم تعديل بواسطه hosslom
  • Like 1
قام بنشر
  في 6‏/10‏/2021 at 19:48, hosslom said:

السلام عليكم اخوتي الكرام

محتاج مثال لكود vba لإنشاء جدول وتحديد نوع الحقول ( رقم - نص - تاريخ -) وخاصة الحقل من النوع yes/no

جزاكم الله كل خير

Expand  

 Dim db As dao.Database
    Dim tdf As dao.TableDef
    Dim fld As dao.Field
    Set db = CurrentDb()
    Set tdf = db.CreateTableDef("tbl " & Text11)
    With tdf
    Set fld = .CreateField("ID", dbLong)
    fld.Attributes = dbAutoIncrField + dbFixedField
    .Fields.Append fld
    .Fields.Append .CreateField("No", DB_DOUBLE)
    .Fields.Append .CreateField("Inbox", dbText, 255)   

        .  .Fields.Append .CreateField("Data", dbDate)
End With
On Error GoTo x
db.TableDefs.Append tdf
Set fld = Nothing
Set tdf = Nothing
Application.RefreshDatabaseWindow
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing
x:

قام بنشر
  في 6‏/10‏/2021 at 19:48, hosslom said:

السلام عليكم اخوتي الكرام

محتاج مثال لكود vba لإنشاء جدول وتحديد نوع الحقول ( رقم - نص - تاريخ -) وخاصة الحقل من النوع yes/no

جزاكم الله كل خير

Expand  

 

تفضل <<<<<<<<<>>>>>>>>>

Dim strSQL1 As String
strSQL1 = "CREATE TABLE [kanory] ([ProductID] AUTOINCREMENT,[ProductName] TEXT(40)  NOT NULL,[SupplierID] LONG,[BirthDate] DATETIME,[CategoryID] LONG,[QuantityPerUnit] TEXT(20),[UnitPrice] CURRENCY,[UnitsInStock] SMALLINT,[UnitsOnOrder] SMALLINT,[ReorderLevel] SMALLINT,[Discontinued] BIT NOT NULL,CONSTRAINT [PrimaryKey] PRIMARY KEY ([ProductID]));"
DoCmd.RunSQL strSQL1

 

اسف اخي الكريم @عبد اللطيف سلوم يبدو ان المشاركيتن في في الوقت .... لكن الطريقتين مختلفتين للفائدة .....

  • Like 3
قام بنشر
  في 6‏/10‏/2021 at 20:15, عبد اللطيف سلوم said:

 Dim db As dao.Database
    Dim tdf As dao.TableDef
    Dim fld As dao.Field
    Set db = CurrentDb()
    Set tdf = db.CreateTableDef("tbl " & Text11)
    With tdf
    Set fld = .CreateField("ID", dbLong)
    fld.Attributes = dbAutoIncrField + dbFixedField
    .Fields.Append fld
    .Fields.Append .CreateField("No", DB_DOUBLE)
    .Fields.Append .CreateField("Inbox", dbText, 255)   

        .  .Fields.Append .CreateField("Data", dbDate)
End With
On Error GoTo x
db.TableDefs.Append tdf
Set fld = Nothing
Set tdf = Nothing
Application.RefreshDatabaseWindow
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing
x:

Expand  

لطفا احذف النقطة المشار اليها بسهم احمر 

2021-10-06_231856.png

قام بنشر
  في 6‏/10‏/2021 at 20:15, عبد اللطيف سلوم said:

Dim db As dao.Database
    Dim tdf As dao.TableDef
    Dim fld As dao.Field
    Set db = CurrentDb()
    Set tdf = db.CreateTableDef("tbl " & Text11)
    With tdf
    Set fld = .CreateField("ID", dbLong)
    fld.Attributes = dbAutoIncrField + dbFixedField
    .Fields.Append fld
    .Fields.Append .CreateField("No", DB_DOUBLE)
    .Fields.Append .CreateField("Inbox", dbText, 255)   

        .  .Fields.Append .CreateField("Data", dbDate)
End With
On Error GoTo x
db.TableDefs.Append tdf
Set fld = Nothing
Set tdf = Nothing
Application.RefreshDatabaseWindow
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing
x:

Expand  

جزاك الله كل خير اخي الكريم

ولكن ماذا عن الحقل Yes/no

قام بنشر
  في 6‏/10‏/2021 at 20:15, kanory said:

اسف اخي الكريم @عبد اللطيف سلوم يبدو ان المشاركيتن في في الوقت .... لكن الطريقتين مختلفتين للفائدة .....

Expand  

كل المحبة والاحترام 

منكم نستفيد صديقي

  • Thanks 1
قام بنشر
  في 6‏/10‏/2021 at 20:15, kanory said:
Dim strSQL1 As String
strSQL1 = "CREATE TABLE [kanory] ([ProductID] AUTOINCREMENT,[ProductName] TEXT(40)  NOT NULL,[SupplierID] LONG,[BirthDate] DATETIME,[CategoryID] LONG,[QuantityPerUnit] TEXT(20),[UnitPrice] CURRENCY,[UnitsInStock] SMALLINT,[UnitsOnOrder] SMALLINT,[ReorderLevel] SMALLINT,[Discontinued] BIT NOT NULL,CONSTRAINT [PrimaryKey] PRIMARY KEY ([ProductID]));"
DoCmd.RunSQL strSQL1
Expand  

جزاك الله كل خير اخي الكريم

وماذا عن الحقل من النوع yes/no

قام بنشر
  في 6‏/10‏/2021 at 20:21, hosslom said:

جزاك الله كل خير اخي الكريم

وماذا عن الحقل من النوع yes/no

Expand  

يا اخي هل طبقك الكود قبل السؤال .... وفتحت على خصائص الجدول ..... ؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟

1.png

  • Like 2
قام بنشر (معدل)
  في 6‏/10‏/2021 at 20:19, hosslom said:

جزاك الله كل خير اخي الكريم

ولكن ماذا عن الحقل Yes/no

Expand  

  dim strSQL as string
      strSQL = "CREATE TABLE tblStatus ( " & _
                "fldCheck yesno )"

تم تعديل بواسطه عبد اللطيف سلوم
اضافة تفصيلات
قام بنشر
  في 6‏/10‏/2021 at 20:15, kanory said:
Dim strSQL1 As String
strSQL1 = "CREATE TABLE [kanory] ([ProductID] AUTOINCREMENT,[ProductName] TEXT(40)  NOT NULL,[SupplierID] LONG,[BirthDate] DATETIME,[CategoryID] LONG,[QuantityPerUnit] TEXT(20),[UnitPrice] CURRENCY,[UnitsInStock] SMALLINT,[UnitsOnOrder] SMALLINT,[ReorderLevel] SMALLINT,[Discontinued] BIT NOT NULL,CONSTRAINT [PrimaryKey] PRIMARY KEY ([ProductID]));"
DoCmd.RunSQL strSQL1
Expand  

عزرا احي الكريم

عند تنفيذ الكود يعطي الخطا

Capture.JPG

قام بنشر
  في 6‏/10‏/2021 at 19:48, hosslom said:

السلام عليكم اخوتي الكرام

محتاج مثال لكود vba لإنشاء جدول وتحديد نوع الحقول ( رقم - نص - تاريخ -) وخاصة الحقل من النوع yes/no

جزاكم الله كل خير

Expand  

ملف العمل مع تطبيق الكود

creat table.accdbFetching info...

قام بنشر (معدل)
  في 6‏/10‏/2021 at 20:34, hosslom said:
Dim strSQL1 As String
strSQL1 = "CREATE TABLE [kanory] ([ProductID] AUTOINCREMENT,[ProductName] TEXT(40)  NOT NULL,[SupplierID] LONG,[BirthDate] DATETIME,[CategoryID] LONG,[QuantityPerUnit] TEXT(20),[UnitPrice] CURRENCY,[UnitsInStock] SMALLINT,[UnitsOnOrder] SMALLINT,[ReorderLevel] SMALLINT,[Discontinued] BIT NOT NULL,CONSTRAINT [PrimaryKey] PRIMARY KEY ([ProductID]));"
DoCmd.RunSQL strSQL1
Expand  

اشتغل الكود جزاك الله كل خير اخي الكريم

اطمع في استفسار اخر ماذا اذا اردت استخدام الامر لعمل الجدول في قاعده خارجية وليست الحاليه

وايضا استخدام ALTER لاستبدال نوع الحقل باخر ممكن الصيغه واسف للإطاله

جزاك الله كل خير

 

  في 6‏/10‏/2021 at 20:41, عبد اللطيف سلوم said:

ملف العمل مع تطبيق الكود

Expand  

شكرا جزيلا اخي الكريم وجعله الله في ميزان حساناتك ان شاء الله

 

تم تعديل بواسطه hosslom
قام بنشر
  في 6‏/10‏/2021 at 20:50, hosslom said:

اشتغل الكود جزاك الله كل خير اخي الكريم

اطمع في استفسار اخر ماذا اذا اردت استخدام الامر لعمل الجدول في قاعده خارجية وليست الحاليه

وايضا استخدام ALTER لاستبدال نوع الحقل باخر ممكن الصيغه واسف للإطاله

جزاك الله كل خير

Expand  

 

لاضافة جدول في قاعدة خارجية استخدم الاتي <<<<<<<>>>>>>>>

Dim msgstyle
Dim strSQL1 As String
Dim b As New Access.Application
Set b = CreateObject("Access.Application")
b.OpenCurrentDatabase (Me.txtPath)
strSQL1 = "CREATE TABLE [kanory] ([ProductID] AUTOINCREMENT,[ProductName] TEXT(40)  NOT NULL,[SupplierID] LONG,[BirthDate] DATETIME,[CategoryID] LONG,[QuantityPerUnit] TEXT(20),[UnitPrice] CURRENCY,[UnitsInStock] SMALLINT,[UnitsOnOrder] SMALLINT,[ReorderLevel] SMALLINT,[Discontinued] BIT NOT NULL,CONSTRAINT [PrimaryKey] PRIMARY KEY ([ProductID]));"
b.DoCmd.RunSQL strSQL1
MsgBox Space(20) & "تم انشاء الجدول Kanory بنجاح.." & Space(20), msgstyle, "للمعلومية"
 Set b = Nothing

 

اما لتعديل خصائص حقل موجود في الجدول استخدم التالي مع ملاحظة : ان اختلاف البيانات قي الحقل اذا كانت هنا بيانات ممكن تفقدها :::: <<<<<>>>>>>>

 

Dim msgstyle
Dim b As DAO.Database
Dim strFieldName As String
Set b = DBEngine.OpenDatabase(Me.txtPath)
With b.TableDefs("Kanory").Fields("S_Name")
        .Properties.Append .CreateProperty("DisplayControl", dbInteger, AcControlType.acComboBox)
        .Properties.Refresh
End With
MsgBox Space(20) & "تم انشاء الجدول Kanory بنجاح.." & Space(20), msgstyle, "للمعلومية"
b.Close
Set b = Nothing

 

  • Like 4

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