ClimoC
Well-known Member
- Joined
- Aug 21, 2009
- Messages
- 584
Hi
Reposting, as I think I might've put it in the wrong forum.
The following works beautifully, when run from a module in an open Access Database
But in Visual Studio, this executes without error - but all that happens is that the Database, Table, and Query are created - but the .Execute line doesn't insert any records to the table.
Any thoughts? Help please? This is really getting to me and getting in the way of my little development!
Thanks
Reposting, as I think I might've put it in the wrong forum.
The following works beautifully, when run from a module in an open Access Database
Code:
Sub TestDump()
Dim db As Database
Dim LPassThrough As QueryDef, tblDef As TableDef
Dim DStmp As String, DayOnlyStmp As String
DStmp = CStr(Format(Now(), "yyyymmdd_hhmmss"))
DayOnlyStmp = CStr(Format(Now(), "yyyymmdd"))
DStmp = Cstr(Format(Now(), "yyyymmdd"))
Set db = DBEngine.CreateDatabase("C:\Users\climoc\Desktop\" & DStmp, dbLangGeneral)
Set tblDef = db.CreateTableDef(DStmp)
With tblDef
.Fields.Append .CreateField("FIELD1", dbText)
.Fields.Append .CreateField("FIELD2", dbText)
End with
db.TableDefs.Appen(tblDef)
Set LPT = db.CreateQueryDef("qryTmp7")
connstr = "ODBC;Driver={Microsoft ODBC for Oracle};Server=MYSRVR;uid=USER;pwd=A!B2C£"
With LPT
.Connect = newstr
.SQL = "SELECT FIELD1, FIELD2 FROM OraTbl WHERE FIELD2 = 'ATextValue'"
.ReturnsRecords = True
.Close
End With
db.Execute "INSERT INTO " & DStmp & "([FIELD1], [FIELD2]) SELECT qryTmp7.[FIELD1], qryTmp7.[FIELD2] FROM qryTmp7"
db.QueryDefs.Delete "qryTmp7"
End Sub
But in Visual Studio, this executes without error - but all that happens is that the Database, Table, and Query are created - but the .Execute line doesn't insert any records to the table.
Code:
Dim AccApp As New Microsoft.Office.Interop.Access.Application
Dim db As Microsoft.Office.Interop.Access.Dao.Database
Dim LPassThrough As Microsoft.Office.Interop.Access.Dao.QueryDef, tblDef As Microsoft.Office.Interop.Access.Dao.TableDef
Dim DStmp As String, DayOnlyStmp As String
Dim newstr As String
DStmp = Cstr(Format(Now(),"yyyymmdd"))
db = AccApp.DBEngine.CreateDatabase("C:\Users\climoc\Desktop\" & DStmp, Dao.LanuageConstants.dbLangGeneral)
tblDef = db.CreateTableDef(DStmp)
With tblDef
.Fields.Append(.CreateField("FIELD1",10))
.Fields.Append(.CreateField("FIELD2",10))
End with
db.TableDefs.Append(tblDef)
LPT = db.CreateQueryDef("qryTmp7")
connstr = "ODBC;Driver={Microsoft ODBC for Oracle};Server=MYSRVR;uid=USER;pwd=A!B2C£"
With LPT
.Connect() = newstr
.SQL = "SELECT FIELD1, FIELD2 FROM OraTbl WHERE FIELD2 = 'ATextValue'"
.ReturnsRecords() = True
.Close()
End With
db.Execute("INSERT INTO " & DStmp & "([FIELD1], [FIELD2]) SELECT qryTmp7.[FIELD1], qryTmp7.[FIELD2] FROM qryTmp7")
Any thoughts? Help please? This is really getting to me and getting in the way of my little development!
Thanks