Link to home
Start Free TrialLog in
Avatar of chillsnthrills
chillsnthrills

asked on

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
Avatar of chillsnthrills
chillsnthrills

ASKER

this is urgent...plz reply soon
Hi chillsnthrills,
You can help us answer ASAP by posting the code you already have written....

Dabas
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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


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?


the link u've given is not opening
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?
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
     

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...."

???
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.

Actualy MYLim that is exactly what I have been saying in my posts. : )
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.
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?
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
no, even this doesn;t work...can u write up in code what u mean to say? i want ms access 2000 database