PDA

Click to See Complete Forum and Search --> : Can't Create Database in RunTime


elpower
Oct 3rd, 2000, 06:04 PM
Hi,

I have been trying to create a database file during runtime. and i keep getting an error message "Argument not optional"


this is the coding i am trying to use.
Can anyone help me with this?

Thanks in advance.
EL.

Public DbFile As Database
Public RstFile As Recordset
Public FileName As String
Public TblFile As TableDef
Public IdxFile As Index
Public FLD As Field
Public WrkDefault As Workspace
Public DbsNew As Database

Public Sub CreateDatabase()
FileName = App.Path & "\database.mdb"
If Dir(FileName) <> "" Then
'open database file
Set DbsNew = OpenDatabase(FileName)
Set RstFile = DbFile.OpenRecordset("Recordset")
Else
Set WrkDefault = DBEngine.Workspaces(0)
Set DbsNew = CreateDatabase(FileName) ' create data file
Set DbsNew = WrkDefault.CreateDatabase(FileName)
Set TblFile = DbFile.CreateTableDef("Recordset") ' create recordset
With TblFile
.Fields.Append .CreateField("FieldName", dbText, 10)
DbFile.TableDefs.Append TblFile
End With
Set IdxFile = TblFile.CreateIndex("IdxFile")
Set FLD = IdxFile.CreateField("Fieldname")
With IdxFile
.Primary = True
.Unique = True
.Required = True
End With
IdxFile.Fields.Append FLD
TblFile.Indexes.Append IdxFile
DbFile.Close
End If
End Sub

bar
Oct 4th, 2000, 05:22 AM
In your createdatabase method you have to specify the locale information. If you're not sure which to use there is a general one. Here is an example.

Set DbsNew = CreateDatabase(FileName, dbLangGeneral)

That should solve your problem.