NewAccessDatabase

  • Thread starter Thread starter Douglas J. Steele
  • Start date Start date
D

Douglas J. Steele

There's no need to instantiate appAccess and use the NewCurrentDatabase.

If strDB already exists, use

Set dbs = OpenDatabase(strDB)

If it doesn't exist, use

Set dbs = CreateDatabase(strDB)
 
Douglas J. Steele said:
There's no need to instantiate appAccess and use the NewCurrentDatabase.


The code is from a help-file example for the NewCurrentDatabase method.
 
Dirk Goldgar said:
The code is from a help-file example for the NewCurrentDatabase method.

So it is, I see.

That doesn't mean it's appropriate though. <g>
 
Thank you I'm using Office Access 2003Why this code not work? And this
message box appear to
me?'''''''''''''''''''''''''''''''''''''''''''''''''''Runtime error '91'Object
variable or with block variable not set
'''''''''''''''''''''''''''''''''''''''''''''''''''' Include following in
Declarations section of module.Dim appAccess As Access.Application Sub
NewAccessDatabase() Dim dbs As Object, tdf As Object, fld As Variant
Dim strDB As String Const DB_Text As Long = 10 Const FldLen As Integer
= 40 ' Initialize string to database path. strDB = "C:\Newdb.mdb"
' Create new instance of Microsoft Access. Set appAccess = _
CreateObject("Access.Application.9") ' Open database in Microsoft Access
window.'''''''''''''''''''''''''''''''''''''''''''''''''' This is error line
appAccess.NewCurrentDatabase strDB'''''''''''''''''''''''''''''''''''''''''''''''''
' Get Database object variable. Set dbs = appAccess.CurrentDb ' Create
new table. Set tdf = dbs.CreateTableDef("Contacts") ' Create field in
new table. Set fld = tdf. _ CreateField("CompanyName", DB_Text,
FldLen) ' Append Field and TableDef objects. tdf.Fields.Append fld
dbs.TableDefs.Append tdf Set appAccess = NothingEnd Sub
 
I'm Sorry
but this error appear to me
Argument not optional (Error 449)
and stop on line
Set dbs = CreateDatabase(strDB)
'''''''
The code
Sub NewAccessDatabase()
' On Error Resume Next
Dim dbs As Object
Dim tdf As Object
Dim fld As Variant
Dim strDB As String
Dim appAccess As Object
Const DB_Text As Long = 10
Const FldLen As Integer = 40

' Initialize string to database path.
strDB = "C:\Newdb.mdb"
Set dbs = CreateDatabase(strDB)

' Create new table.
Set tdf = dbs.CreateTableDef("Contacts")
' ' Create field in new table.
Set fld = tdf. _
CreateField("CompanyName", DB_Text, FldLen)
' ' Append Field and TableDef objects.
tdf.Fields.Append fld
dbs.TableDefs.Append tdf
Set dbs = Nothing
End Sub
 
a said:
I'm Sorry
but this error appear to me
Argument not optional (Error 449)
and stop on line
Set dbs = CreateDatabase(strDB)


If you look in the online help for CreateDatabase method (DAO), you'll find
that it requires a second argument called "locale". This argument
established the collating order for the new database. I always use the
dbLangGeneral constant for this, as in:

Set dbs = DBEngine.CreateDatabase(strDB, dbLangGeneral)

I'm don't know what your proper locale is, though, so you may want to use
one of the other available constants. Here's the lis from the help topic:

dbLangGeneral - English, German, French, Portuguese, Italian, and Modern
Spanish
dbLangArabic - Arabic
dbLangChineseSimplified - Simplified Chinese
dbLangChineseTraditional - Traditional Chinese
dbLangCyrillic - Russian
dbLangCzech - Czech
dbLangDutch - Dutch
dbLangGreek - Greek
dbLangHebrew - Hebrew
dbLangHungarian - Hungarian
dbLangIcelandic - Icelandic
dbLangJapanese - Japanese
dbLangKorean - Korean
dbLangNorwDan - Norwegian and Danish
dbLangPolish - Polish
dbLangSlovenian - Slovenian
dbLangSpanish - Traditional Spanish
dbLangSwedFin - Swedish and Finnish
dbLangThai - Thai
dbLangTurkish - Turkish
 
Back
Top