View Single Post
 
Old January 12th, 2004, 11:18 PM
ecaro ecaro is offline
Registered User
 
Join Date: Jan 2004
Location: Aguadilla, PR, USA.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 Hi Edgar,

There is no "code in VB" to send you. However, as I suggested, you should be able to change the ASP code to VB code by removing the comments for the string data type declarations.

What problems are you having? Are you getting any errors?

Maybe you can post the code you have so far so I can take a look at it.

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Hi Imar,

    This routine works fine "CreateAccessDatabase".
I send you the complete of routine called "CreateAccessTable"
I put an asterisk at the fail line in VB compilation runtime.
This is the error message in the VB msgbox :
  "Runtime error '3001':"
"Arguments are of the wrong type, are out of acceptable range, or are conflict with one another"

******** Check the asterisk at the line **********
    Sub CreateAccessTable(sDatabaseToCreate)
        'Dim catDB ' As ADOX.Catalog
        Dim catDB As Object
        'Set catDB = Server.CreateObject("ADOX.Catalog")
        Set catDB = CreateObject("ADOX.Catalog")
        ' Open the catalog
        catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & sDatabaseToCreate
        'Dim tblNew ' As ADOX.Table
        Dim tblNew As Object
        'Set tblNew = Server.CreateObject("ADOX.Table")
        Set tblNew = CreateObject("ADOX.Table")
        tblNew.Name = "Contacts"

        ' First Create an Autonumber column, called ID.
        ' This is just for demonstration purposes.
        ' We could have done this below with all the other columns as well
        'Dim col ' As ADOX.Column
        Dim col As Object
        'Set col = Server.CreateObject("ADOX.Column")
        Set col = CreateObject("ADOX.Column")
        With col
            .ParentCatalog = catDB
            .Type = adText * The error appears when trace here.
            .Name = "ID"
            .Properties("Autoincrement") = True
        End With
        tblNew.Columns.Append col

        ' Now add the rest of the columns
        With tblNew
            ' Create fields and append them to the
            ' Columns collection of the new Table object.
            With .Columns
                .Append "NumberColumn", adinteger *Also the same
                .Append "FirstName", adVarWChar *Also the same
                .Append "LastName", adVarWChar *Also the same
                .Append "Phone", adVarWChar *Also the same
                .Append "Notes", adLongVarWChar *Also the same
                End With

                Dim adColNullable ' Is not defined in adovbs.inc,
                ' so we need to define it here.
                ' The other option is adColFixed with a value of 1
                adColNullable = 2
                With .Columns("FirstName")
                .Attributes = adColNullable
            End With
        End With

        ' Add the new Table to the Tables collection of the database.
        catDB.Tables.Append tblNew
        Set col = Nothing
        Set tblNew = Nothing
        Set catDB = Nothing
    End Sub

**** This is the complete VB program ****

    Sub CreateAccessDatabase(sDatabaseToCreate)
        'Dim catNewDB ' As ADOX.Catalog
        Dim catNewDB As Object
        'Set catNewDB = Server.CreateObject("ADOX.Catalog")
        Set catNewDB = CreateObject("ADOX.Catalog")
        catNewDB.Create "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & sDatabaseToCreate & _
        ";Jet OLEDB:Engine Type=5;"
        ' Engine Type=5 = Access 2000 Database
        ' Engine Type=4 = Access 97 Database
        Set catNewDB = Nothing
    End Sub
    Sub CreateAccessTable(sDatabaseToCreate)
        'Dim catDB ' As ADOX.Catalog
        Dim catDB As Object
        'Set catDB = Server.CreateObject("ADOX.Catalog")
        Set catDB = CreateObject("ADOX.Catalog")
        ' Open the catalog
        catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;"_
        & "Data Source=" & sDatabaseToCreate
        'Dim tblNew ' As ADOX.Table
        Dim tblNew As Object
        'Set tblNew = Server.CreateObject("ADOX.Table")
        Set tblNew = CreateObject("ADOX.Table")
        tblNew.Name = "Contacts"

        ' First Create an Autonumber column, called ID.
        ' This is just for demonstration purposes.
        ' We could have done this below with all the other columns as
        ' well
        'Dim col ' As ADOX.Column
        Dim col As Object
        'Set col = Server.CreateObject("ADOX.Column")
        Set col = CreateObject("ADOX.Column")
        With col
            .ParentCatalog = catDB
            .Type = adText
            .Name = "ID"
            .Properties("Autoincrement") = True
        End With
        tblNew.Columns.Append col

        ' Now add the rest of the columns
        With tblNew
            ' Create fields and append them to the
            ' Columns collection of the new Table object.
            With .Columns
                .Append "NumberColumn", adinteger
                .Append "FirstName", adVarWChar
                .Append "LastName", adVarWChar
                .Append "Phone", adVarWChar
                .Append "Notes", adLongVarWChar
                End With

                Dim adColNullable ' Is not defined in adovbs.inc,
                ' so we need to define it here.
                ' The other option is adColFixed with a value of 1
                adColNullable = 2
                With .Columns("FirstName")
                .Attributes = adColNullable
            End With
        End With

        ' Add the new Table to the Tables collection of the database.
        catDB.Tables.Append tblNew
        Set col = Nothing
        Set tblNew = Nothing
        Set catDB = Nothing
    End Sub
Private Sub Form_Load()
    sDatabaseName = "C:\MyNewDatabase.mdb"
    ' First call the Create Database method
    CreateAccessDatabase sDatabaseName
    ' Then add a table and columns to this database
    CreateAccessTable sDatabaseName
    MsgBox "Database has been created successfully!"
End Sub

Thanks,

  Any question reply to me :)

Edgar


Edgar Caro