Problem
Hi there,
I am trying to get the above code to work, however i am struggling with it...
I have created a database using the following:
Code:
Sub CreateNewMDB(FileName, Format)
Dim Engine
Set Engine = CreateObject("DAO.DBEngine.36")
Engine.CreateDatabase FileName, ";LANGID=0x0409;CP=1252;COUNTRY=0", Format
End Sub
'Create Access2000 database
CreateNewMDB "c:\localdata\test\a2000.mdb", dbVersion40
and it creates the database with no problems and I am able to open the database in Access and use it like any other database.
However...
When using the code that was supplied above to create a table and enter the data in it (from a csv file, in correct format)
Then i get a error stating "Cannot update. Database or object is read-only" on Line 30.
Here is the code i am using to test this...
Code:
Dim oJet ' DAO.DBEngine
Dim oDB ' DAO.Database
Dim strSQL ' String
MDBFile = "c:\localdata\test\a2000.mdb"
TableName = "Table1"
Folderpath = "c:\localdata\test\"
TextFileName = Table1
Extension = csv
Set oJet = CreateObject("DAO.DBEngine.36")
Set oDB = oJet.OpenDatabase(MDBFile)
'strSQL1 = "CREATE TABLE Table1 (Field1 char(100),Field2 char(100))"
'oDB.Execute strSQL1
strSQL = "SELECT * INTO " & TableName _
& " FROM [Text;HDR=Yes;Database=" & FolderPath _
& ";].[" & TextFileName & "#" & Extension & "];"
oDB.Execute strSQL
oDB.Close
The strSQL1 statement is able to create a table in the database without any problems. Therefore i beleive it is something to do with the way that it is importing the data from the csv file?
Any help would be very much appreciated on this.
Many Thanks
Freddy