Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I change all the column values (Nullable=True and Allow Zero Length=True) in a table except the PersonalID column?

When the script is executed, I get the error: "-2147217887 - Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done."

This is the code for just one table. I need to create more tables so setting Nullable property of each column is not practical.
Please help!

Here is the code:
VB
Public Sub DBcreation()
Dim tbl As New Table
Dim cat As New ADOX.Catalog
Dim col As ADOX.Column
Dim prp As ADOX.Property
Dim oCn As ADODB.Connection
Dim sConStr As String


'Set Connection string
 sConStr = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=" & App.Path & "\mydbase.mdb" & ";" & _
           "Jet OLEDB:Engine Type=4;"
' 1) Create the DataBase
 cat.Create sConStr

' 2) Create Table name "PDetails"
 tbl.Name = "PDetails"
' 3) Add  Fields
 With tbl.Columns
 .Append "PersonalID", adInteger  'Number
 .Append "GHName", adVarWChar, 50 'Text
 .Append "FirstName", adVarWChar, 50 'Text
 .Append "FHName", adVarWChar, 50 'Text
 .Append "Surname", adVarWChar, 50 'Text
 .Append "BirthDate", adDate
 .Append "Gender", adVarWChar, 10 'Text
 .Append "Address", adLongVarWChar 'Memo
 .Append "Pincode", adInteger  'Number
 .Append "MobileNo", adInteger 'Number
 .Append "HomeNo", adInteger 'Number
 .Append "MaritalStatus", adVarWChar, 10 'Text
 .Append "Profession", adVarWChar, 50 'Text
 .Append "BloodGroup", adVarWChar, 10 'Text
 .Append "Photo", adVarWChar, 50 'Text

 ' 4) 'Set the field properties.


 With !PersonalID 'AutoNumber.
 .ParentCatalog = cat
 .Properties("Autoincrement") = True
 .Properties("Description") = "Automatically " & _
 "generated unique identifier for this record."
 End With

 With !BirthDate
 Set .ParentCatalog = cat
 .Properties("Jet OLEDB:Column Validation Rule") = _
  "Is Null Or <=Date()"
 .Properties("Jet OLEDB:Column Validation Text") = _
  "Birth date cannot be future."
 End With

 End With
 ' 5) Save the Table to the DataBase
    cat.Tables.Append tbl
' 6) Set Column Properties    
   For Each col In tbl.Columns
   For Each prp In col.Properties
   If col.Name <> "PersonalID" Then
    If prp.Name = "Nullable" Then
    prp.Value = True 'error generated
    '-2147217887 - Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
    End If
    End If
  Next
  Next

 'Clean up

  Set tbl = Nothing
  Set cat = Nothing
  set prp = Nothing
  End Sub
Posted
Updated 7-Aug-10 1:51am
v4

1 solution

I would suggest that instead of trying to create your tables with code, create a blank database with all of the table structures already created. Then, add that db as a reference in your project and then when you want to create a new database, you just write that db to the file system.

And hopefully this is a typo from when you copied if over, but you have:

VB
With !PersonaltID 'AutoNumber.

(you put a "t" in between Personal and ID)

I would also guess that you can't tell it to change the Nullable property. That is set based on the type of the column. For example, an integer cannot be nullable AFAIK.
 
Share this answer
 
Comments
darryl_co 7-Aug-10 7:50am    
I want to create the the database by code so that if the database file is deleted a new one can be create automatically and the compiled exe file is also small.sorry for the typing error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900