Solved

Create MS Access Database.

Posted on 2003-11-10
16
36,337 Views
Last Modified: 2013-12-25
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
Comment
Question by:chillsnthrills
  • 6
  • 5
  • 3
  • +2
16 Comments
 

Author Comment

by:chillsnthrills
Comment Utility
this is urgent...plz reply soon
0
 
LVL 27

Expert Comment

by:Dabas
Comment Utility
Hi chillsnthrills,
You can help us answer ASAP by posting the code you already have written....

Dabas
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 150 total points
Comment Utility
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
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
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
 

Author Comment

by:chillsnthrills
Comment Utility
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
 

Author Comment

by:chillsnthrills
Comment Utility
the link u've given is not opening
0
 

Author Comment

by:chillsnthrills
Comment Utility
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
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 8

Expert Comment

by:MYLim
Comment Utility
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
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
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
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
Actualy MYLim that is exactly what I have been saying in my posts. : )
0
 
LVL 9

Expert Comment

by:Dang123
Comment Utility
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
 

Author Comment

by:chillsnthrills
Comment Utility
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
 
LVL 8

Expert Comment

by:MYLim
Comment Utility
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
 

Author Comment

by:chillsnthrills
Comment Utility
no, even this doesn;t work...can u write up in code what u mean to say? i want ms access 2000 database
0
 
LVL 8

Expert Comment

by:MYLim
Comment Utility
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now