Solved

VB6 code to create a db and Table

Posted on 2002-04-16
2
236 Views
Last Modified: 2010-05-02
I need help with this vb6 code. It worked at one time and created a database m086.mdb
However, now it gives me an ISAM error before the create. I can't figure out why.

Also, when it DID create the m086.mdb it would not continue and create a table in the new db. How do I then get the table into the m086.mdb?

Private Sub CreateClass_Click()
'CreateDatabase()
On Error GoTo ErrorCreateDB
Dim Cat As New ADOX.Catalog
Dim Tbl(5) As ADOX.Table
Dim Idx() As ADOX.Index
Dim msgErrR As Integer
Dim sCnn As String
NuevaDB$ = "m086"

sCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:reEngine Type=5;" + "Data Source=" + NuevaDB$ + ".mdb"

'error next statement:"can not find installable
'ISAM.
' At one time I did NOT get this error now I do !

Cat.Create sCnn
'what code do I need HERE to create a table with specs below?

Stop
Set Tbl(5) = New ADOX.Table
Stop
Set Tbl(5).ParentCatalog = Cat
Stop
With Tbl(5)

.Name = "ClassList"

.Columns.Append "Password", adVarWChar, 5

.Columns.Append "StudenNumber", adInteger

.Columns("StudenNumber").Properties("AutoIncrement").Value = True

.Columns("StudenNumber").Properties("Nullable").Value = False

.Columns.Append "StudentFirst", adVarWChar, 25

.Columns("StudentFirst").Properties("Nullable").Value = False

.Columns.Append "StudentLast", adVarWChar, 25

.Columns("StudentLast").Properties("Nullable").Value = False

.Columns.Append "TeacherFirst", adVarWChar, 25

.Columns("TeacherFirst").Properties("Nullable").Value = False

.Columns.Append "TeacherLast", adVarWChar, 25

.Columns("TeacherLast").Properties("Nullable").Value = False
End With

Stop
ReDim Idx(1)
Set Idx(0) = New ADOX.Index

Idx(0).Name = "ClassID"

Idx(0).IndexNulls = adIndexNullsAllow

Idx(0).Unique = True

Idx(0).Columns.Append "Password"
Set Idx(1) = New ADOX.Index

Idx(1).Name = "PrimaryKey"

Idx(1).PrimaryKey = True

Idx(1).Unique = True

Idx(1).Columns.Append "StudenNumber"
For i = 0 To UBound(Idx)

Tbl(5).Indexes.Append Idx(i)
Next i
Stop
Cat.Tables.Append Tbl(5)
Stop
Set Cat = Nothing
Exit Sub

ErrorCreateDB:

msgErrR = MsgBox(" Error No. " & Err & " " & vbCrLf & Error, vbCritical + vbAbortRetryIgnore, "Code Gen Error")

Select Case msgErrR

Case Is = vbAbort

If Not (Cat Is Nothing) Then

Set Cat = Nothing

End If

Exit Sub

Case Is = vbRetry

Resume Next

Case Is = vbIgnore

Resume

End Select
End Sub


0
Comment
Question by:mathprof
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
riaz9 earned 100 total points
ID: 6947072
You can try:

Dim catCatalog As New ADOX.Catalog, tblTable As ADOX.Table, colColumn As ADOX.Column

catCatalog.Create "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = " & Database

set tblTable = New ADOX.Table
tblTable.Name = "MyTable"

set colColumn = new ADOX.Column
colColumn.Name = "ColumnName"  '**
colColumn.Type = adVarWChar    '**
colColumn.DefinedSize = 50     '**
colColumn.Attributes = adColNullable  '**  - this still does not set Allow Zero Length Attribute to Zero (it only sets Required to False)

tblTable.Columns.Append colColumn   '**

'** repeat the code to add as many columns needed.

'for columns like datetime you don't need DefinedSize

catCatalog.Tables.Append tblTable

set tblTable = nothing: set colColumn = nothing: set catCatalog = nothing


hope this helps,

riaz
0
 

Author Comment

by:mathprof
ID: 6949064
Thanks Riaz9. I changed the code (see below) modifying a bit what you suggested.

Mathprof


strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" + NuevaDB$ + ".mdb"
    Set catNewDatabase = New ADOX.Catalog
    catNewDatabase.Create strConn
    Set catNewDatabase = Nothing
   
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question