?
Solved

VB6 code to create a db and Table

Posted on 2002-04-16
2
Medium Priority
?
242 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 400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

762 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