Hi guys!
Once more, sorry for the Newbie type query.
I'm trying to write some Access 2003 code in an Access Module to create a new (i.e it doesn't already exist) database.
The code is shown below.
As usual, I've fallen at the first hurdle
On execution of the "Set db = OpenDatabase....." statement, Access complains that it can't find an existing "NewCopy.mdb".
Could some kind person tell me what syntax I should be using, and have a quick look at the subsequent code for the inevitable second hurdle?
Thanks again in anticipation
(Oh, and how do you put "pictures" of code in a question? I usually indent code for clarity, but when I preview the post, the code is all left justified!
)
Option Compare Database
Option Explicit
Private Sub NewDb()
'*
'** variables
'*
Dim rs1 As Recordset
Dim db As Database
Dim td As TableDef
Dim fld As Field
Dim iFields As Integer
'*
'** Open new database.
'*
Set db = OpenDatabase("C:\Users\testi\Acaccess\NewCopy.mdb")
'*
'** Create a pointless sample Table.
'*
Set td = db.TableDefs("SillyTable")
'*
'** Now that the database Table is created, add fields to the Table.
'*
For iFields = 1 To 3 'Just a few....
Set fld = td.CreateField("Field " & CStr(iFields), dbInteger)
td.Fields.Append fld
Next iFields
For iFields = 4 To 6 'Just a few....
Set fld = td.CreateField("String " & CStr(iFields), dbText, 25)
td.Fields.Append fld
Next iFields
End Sub
Once more, sorry for the Newbie type query.
I'm trying to write some Access 2003 code in an Access Module to create a new (i.e it doesn't already exist) database.
The code is shown below.
As usual, I've fallen at the first hurdle

On execution of the "Set db = OpenDatabase....." statement, Access complains that it can't find an existing "NewCopy.mdb".
Could some kind person tell me what syntax I should be using, and have a quick look at the subsequent code for the inevitable second hurdle?
Thanks again in anticipation
(Oh, and how do you put "pictures" of code in a question? I usually indent code for clarity, but when I preview the post, the code is all left justified!

Option Compare Database
Option Explicit
Private Sub NewDb()
'*
'** variables
'*
Dim rs1 As Recordset
Dim db As Database
Dim td As TableDef
Dim fld As Field
Dim iFields As Integer
'*
'** Open new database.
'*
Set db = OpenDatabase("C:\Users\testi\Acaccess\NewCopy.mdb")
'*
'** Create a pointless sample Table.
'*
Set td = db.TableDefs("SillyTable")
'*
'** Now that the database Table is created, add fields to the Table.
'*
For iFields = 1 To 3 'Just a few....
Set fld = td.CreateField("Field " & CStr(iFields), dbInteger)
td.Fields.Append fld
Next iFields
For iFields = 4 To 6 'Just a few....
Set fld = td.CreateField("String " & CStr(iFields), dbText, 25)
td.Fields.Append fld
Next iFields
End Sub