VB6 Building Access from code

Reply

Join Date: Dec 2006
Posts: 3
Reputation: darklynx489 is an unknown quantity at this point 
Solved Threads: 0
darklynx489 darklynx489 is offline Offline
Newbie Poster

VB6 Building Access from code

 
0
  #1
Dec 18th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: VB6 Building Access from code

 
0
  #2
Dec 18th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 3
Reputation: darklynx489 is an unknown quantity at this point 
Solved Threads: 0
darklynx489 darklynx489 is offline Offline
Newbie Poster

Re: VB6 Building Access from code

 
0
  #3
Dec 19th, 2006
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?
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: VB6 Building Access from code

 
0
  #4
Dec 25th, 2006
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC