Solved

Create MS Access Database.

Posted on 2003-11-10
16
36,343 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
ID: 9719912
this is urgent...plz reply soon
0
 
LVL 27

Expert Comment

by:Dabas
ID: 9720079
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
ID: 9722077
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
ID: 9733162
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
ID: 9738130
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
ID: 9745187
the link u've given is not opening
0
 

Author Comment

by:chillsnthrills
ID: 9746112
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
ID: 9747379
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 8

Expert Comment

by:MYLim
ID: 9747422
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
ID: 9747426
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
ID: 9747435
Actualy MYLim that is exactly what I have been saying in my posts. : )
0
 
LVL 9

Expert Comment

by:Dang123
ID: 9747472
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
ID: 9762320
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
ID: 9762359
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
ID: 9795647
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
ID: 9830658
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

914 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

12 Experts available now in Live!

Get 1:1 Help Now