• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 36401
  • Last Modified:

Create MS Access Database.

I want to give my user an option to create a new database or open an existing one...
i am usign common dialog box-save for new database...where the databaseis saved with extension new.mdb. but when i actually see this in my hard disk there is no such file existing? i don't know what is the prob...What i want is this....
->on clicking  new database a new database ( whose name would be specified by user) should be formed alongwith 3 tables having specific fields i want...this should be there for every new database that the user creates througth the interface i have made in Visual Basic 6.0...?
-> and also a connection with this database should be made automatically.
-->when i open a database the connection with that should be formed...

Please help out as early as possible...
thanks in advance...
chillsnthrills
0
chillsnthrills
Asked:
chillsnthrills
  • 6
  • 5
  • 3
  • +2
1 Solution
 
chillsnthrillsAuthor Commented:
this is urgent...plz reply soon
0
 
DabasCommented:
Hi chillsnthrills,
You can help us answer ASAP by posting the code you already have written....

Dabas
0
 
GrahamSkanCommented:
This is one way will create a new Access database.

Set a reference to Microsoft ADO Ext x.x for DDL and Security (ADOX)

Sub DBcreate(DatabaseName As String)

   Dim cat As New ADOX.Catalog
   Dim tbl As New ADOX.Table

   cat.Create "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DatabaseName & ";"
    Set tbl = cat.Tables
   
   With tbl
      .Name = "Table1"
      .Columns.Append "Field1", adVarWChar
      .Columns.Append "Field2", adVarWChar
      .Columns.Append "Field3", adVarWChar
   End With

   cat.Tables.Append tbl
End Sub


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Dang123Commented:
chillsnthrills,
    Here is a link that shows you how to create a new Access database and define the tables in XML to allow you to easily reuse the code again in the future.

http://www.vbip.com/xml/XML2Access/XML2Access-01.asp

Dang123


0
 
chillsnthrillsAuthor Commented:
I am using common dialog box to select a database to be opened. however the error coming up is
" 2147467259(80004005)
could not find installable ISAM
Private Sub MenuOpenDatabase_Click()
On Error GoTo 0
        cmdgmdiform.CancelError = True              'cmdgmdiform is common dialog box
        cmdgmdiform.DialogTitle = "Open Database"
        cmdgmdiform.Filter = "MS Access Databases|*.mdb"
        cmdgmdiform.ShowOpen
        selectdb = cmdgmdiform.FileName
        Set db = New Connection
        db.Provider = "microsoft.jet.oledb.4.0"
        db.Open "DataSource=" & selectdb
        frmtabrate.Show
End Sub
And for making a new database as well...it is stucking on the line...ocat.create....(the code which u've specified...)
Private Sub MenuNewDatabase_Click()
       
         cmdgmdiform.CancelError = True   'cmdgmdiform is common dialog box
        cmdgmdiform.DialogTitle = "Create New Database..."
        cmdgmdiform.Filter = "*.mdb"
        cmdgmdiform.DefaultExt = ".mdb"
        cmdgmdiform.ShowSave
        Call DBCreate.DBCreate(cmdgmdiform.FileName)
       
End Sub

Any Solutions?


0
 
chillsnthrillsAuthor Commented:
the link u've given is not opening
0
 
chillsnthrillsAuthor Commented:
frds..i was able to create the database through ADOX,,,but the problem is that the fields in the database can't be set values accordingto me..
i mean properties of tables like...
-decimal places
-format
-default value
-required
-indexed

How do i set all these?

Can anyone reply soon?
0
 
Dang123Commented:
The third page on the link I posted shows how to do the index with "CREATE INDEX " through ADO like this

    If Len(sIndex) > 0 Then
     sSQL = "CREATE INDEX IX_" & sTableName & " ON " & sTableName & " (" & sIndex & ")"
     conn.Execute sSQL
     If Err Then Err.Raise vbObjectError, "", DBError("Unable to create index", sSQL)
    End If
     

0
 
MYLimCommented:
this is a question i would like to ask:
why nobody subject using ADO to create table.why using ADOX?
EX:
connection.execute "create table...."

???
0
 
Dang123Commented:
Access help says this will give you the format of a column and the required property (Not Null) - Look at "CREATE TABLE Statement"


CREATE [TEMPORARY] TABLE table (field1 type [(size)] [NOT NULL] [WITH COMPRESSION | WITH COMP] [index1] [, field2 type [(size)] [NOT NULL] [index2] [, ...]] [, CONSTRAINT multifieldindex [, ...]])

The CREATE TABLE statement has these parts:

Part Description
table The name of the table to be created.

field1, field2 The name of field or fields to be created in the new table. You must create at least one field.

type The data type of field in the new table.

size The field size in characters (Text and Binary fields only).

index1, index2 A CONSTRAINT clause defining a single-field index. For more information on how to create this index, see CONSTRAINT Clause.

multifieldindex A CONSTRAINT clause defining a multiple-field index. For more information on how to create this index, see CONSTRAINT Clause.


Remarks
Use the CREATE TABLE statement to define a new table and its fields and field constraints. If NOT NULL is specified for a field, then new records are required to have valid data in that field.

A CONSTRAINT clause establishes various restrictions on a field, and can be used to establish the primary key. You can also use the CREATE INDEX statement to create a primary key or additional indexes on existing tables.

You can use NOT NULL on a single field or within a named CONSTRAINT clause that applies to either a single field or to a multiple-field named CONSTRAINT. However, you can apply the NOT NULL restriction only once to a field. Attempting to apply this restriction more than once results in a run-time error.

0
 
Dang123Commented:
Actualy MYLim that is exactly what I have been saying in my posts. : )
0
 
Dang123Commented:
Help says that size is only for Text and Binary fields so I don't see decimal places or default values. But that’s three of the five points you asked about.  Perhaps someone else may have a workaround for these last two.
0
 
chillsnthrillsAuthor Commented:
mylim,,, thatz fine with ur option..but teh problem is it does specify datatype number but not that it should be double or long type and also nothign about autoincrement property.

??????????wht to do now?
0
 
MYLimCommented:
here are the key:
AUTO_INCREMENT = #

===================================
  CREATE TABLE t (
  id INT(11) default NULL auto_increment,
  s char(60) default NULL,
  PRIMARY KEY (id)
===================================
sorry,due to do the Clean Up job,so you may read urself
===================================
http://www.mysql.com/doc/en/SHOW_CREATE_TABLE.html
http://www.mysql.com/doc/en/CREATE_TABLE.html
http://www.1keydata.com/sql/sqlcreate.html
0
 
chillsnthrillsAuthor Commented:
no, even this doesn;t work...can u write up in code what u mean to say? i want ms access 2000 database
0
 
MYLimCommented:
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now