944,039 Members | Top Members by Rank

Ad:
Dec 18th, 2006
0

VB6 Building Access from code

Expand Post »
Hi All!
I've already got the code to create a full Access database from code, but the problem I'm having is that I need the property AllowZeroFill to be enabled in some sections and I'm also having problems getting the AutoIncrement to work.

Here is the code I have so far:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. Option Explicit
  3. Public Function AutoCreateAccess(ByVal sDatabaseToCreate As String) As Boolean
  4. CreateAccessDatabase (sDatabaseToCreate) 'Creates the database
  5.  
  6. Dim catDB As ADOX.Catalog
  7. Dim tblNew As ADOX.Table
  8. Set catDB = New ADOX.Catalog
  9.  
  10. ' Open the catalog
  11. catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  12. "Data Source=" & sDatabaseToCreate
  13. '-------------------------------------------------
  14. ' Create new Table and add the columns
  15. Set tblNew = New ADOX.Table
  16. tblNew.Name = "bellschedule"
  17. With tblNew
  18. With .Columns
  19. .Append "period", adVarWChar, 50
  20. .Append "bellday", adVarWChar, 50
  21. .Append "timefrom", adDate, 8
  22. .Append "timeto", adDate, 8
  23. End With
  24.  
  25. Dim adColNullable
  26. adColNullable = 2
  27. With .Columns("period")
  28. .Attributes = adColNullable 'Unchecks the REQUIRED box
  29. End With
  30. With .Columns("bellday")
  31. .Attributes = adColNullable
  32. End With
  33. With .Columns("timefrom")
  34. .Attributes = adColNullable
  35. End With
  36. With .Columns("timeto")
  37. .Attributes = adColNullable
  38. End With
  39. End With
  40. catDB.Tables.Append tblNew
  41. '-------------------------------------------------'
  42. '-------------------------------------------------
  43. ' Create new Table and add the columns
  44. Set tblNew = New ADOX.Table
  45. tblNew.Name = "schoolinfo"
  46. With tblNew
  47. With .Columns
  48. .Append "schoolname", adVarWChar, 50
  49. .Append "district", adVarWChar, 50
  50. End With
  51.  
  52. With .Columns("schoolname")
  53. .Attributes = adColNullable
  54. End With
  55. With .Columns("district")
  56. .Attributes = adColNullable
  57. End With
  58. End With
  59. catDB.Tables.Append tblNew
  60. '-------------------------------------------------
  61. ' Create new Table and add the columns
  62. Set tblNew = New ADOX.Table
  63. tblNew.Name = "students"
  64. With tblNew
  65. With .Columns
  66. .Append "firstname", adVarWChar, 50
  67. .Append "lastname", adVarWChar, 50
  68. .Append "DOB", adDate, 8
  69. .Append "picture", adBinary
  70. .Append "id", adVarWChar, 25
  71. .Append "gender", adVarWChar, 2
  72. .Append "middlename", adVarWChar, 50
  73.  
  74. End With
  75.  
  76. With .Columns("firstname")
  77. .Attributes = adColNullable
  78. End With
  79. With .Columns("lastname")
  80. .Attributes = adColNullable
  81. End With
  82. With .Columns("DOB")
  83. .Attributes = adColNullable
  84. End With
  85. With .Columns("picture")
  86. .Attributes = adColNullable
  87. End With
  88. With .Columns("id")
  89. .Attributes = adColNullable
  90. End With
  91. With .Columns("gender")
  92. .Attributes = adColNullable
  93. End With
  94. With .Columns("middlename")
  95. .Attributes = adColNullable
  96. End With
  97. End With
  98. catDB.Tables.Append tblNew
  99. '-------------------------------------------------
  100. ' Create new Table and add the columns
  101. Set tblNew = New ADOX.Table
  102. tblNew.Name = "tardies"
  103. With tblNew
  104. .ParentCatalog = catDB ' need this to recognize special properties
  105. With .Columns
  106. .Append "id", adVarWChar, 25
  107. .Append "tdate", adDate, 8
  108. .Append "ttime", adDate, 8
  109. .Append "period", adVarWChar, 25
  110. .Append "tardyid", adLongVarWChar, 4
  111. End With
  112.  
  113. With .Columns("id")
  114. .Attributes = adColNullable
  115. End With
  116. With .Columns("tdate")
  117. .Attributes = adColNullable
  118. End With
  119. With .Columns("ttime")
  120. .Attributes = adColNullable
  121. End With
  122. With .Columns("period")
  123. .Attributes = adColNullable
  124. End With
  125. With .Columns("tardyid")
  126. .Properties("AutoIncrement") = True 'HERE IS THE PROBELM!!
  127. .Attributes = adColNullable
  128. End With
  129. End With
  130. catDB.Tables.Append tblNew
  131. '------------------------------------------'
  132. Set tblNew = Nothing
  133. Set catDB = Nothing
  134. AutoCreateAccess = True
  135. End Function

im building this for my school, and im leaving the school in less than a week, any help would be greatly apprecitated! =D


also, here is the code for the CreateAccessDatabase function:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Public Function CreateAccessDatabase(ByVal sDatabaseToCreate As String) As Boolean
  2. Dim catNewDB As ADOX.Catalog
  3. Set catNewDB = New ADOX.Catalog
  4. catNewDB.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  5. "Data Source=" & sDatabaseToCreate & _
  6. ";Jet OLEDB:Engine Type=4;"
  7. ' Engine Type=5 = Access 2000 Database
  8. ' Engine Type=4 = Access 97 Database
  9.  
  10. Set catNewDB = Nothing
  11. CreateAccessDatabase = True
  12. End Function
Last edited by darklynx489; Dec 18th, 2006 at 12:01 pm. Reason: adding support for inquisitive users
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darklynx489 is offline Offline
3 posts
since Dec 2006
Dec 18th, 2006
0

Re: VB6 Building Access from code

Hi,

Try this :
After Appending the Column say MyColumn

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1.  
  2. Dim cat As New ADOX.Catalog
  3.  
  4. Set cat.ActiveConnection = CurrentProject.Connection
  5.  
  6. With !MyColumn
  7. .Append "MyColumn", adWChar, 50
  8. Set .ParentCatalog = cat
  9. .Properties("Jet OLEDB:Allow Zero Length") = True
  10. .Properties("Nullable") = True
  11. End With
  12.  
  13.  
  14. With .Columns
  15. .Append "Auto_ID", adInteger
  16. With !Auto_ID
  17. Set .ParentCatalog = cat
  18. .Properties("Autoincrement") = True
  19. .Properties("seed") = CLng(20)
  20. .Properties("increment") = CLng(20)
  21. End With
  22. End With

Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006
Dec 19th, 2006
0

Re: VB6 Building Access from code

Hmm.. I get an Invalid or Unqualified Reference error.
I've tried to integrate it into my code, with backlash. If you wouldn't mind, how exactly should I go about putting your code into mine?
After I build the table or inside my .columns section?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
darklynx489 is offline Offline
3 posts
since Dec 2006
Dec 25th, 2006
0

Re: VB6 Building Access from code

Hi,


Check these Sites :
For Allow Zero Length:
http://www.gab2001uk.com/visualbasic...tion/index.htm

For Auto Increment :
http://support.microsoft.com/kb/275252

Regards
Veena
Reputation Points: 84
Solved Threads: 140
Posting Shark
QVeen72 is offline Offline
923 posts
since Nov 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Listview
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Help on making and using Database in VB





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC