W
Waterman
Hi!
I would like to create a table that exists only in memory
while the subroutine is running. I get hung up when it
comes time to refresh the table defs. What I've written
so far only works if I append the table. What am I
missing?
Sub PhantomTable()
Dim dbs As Database
Dim rst, rst1, rst2 As Recordset
Dim tdf As TableDef
Dim strSQL, txtFirst, txtSecond As String
Set dbs = OpenDatabase("C:\Working
Models\PhantomTable.mdb")
Set tdf = dbs.CreateTableDef("Phantom")
With tdf
.Fields.Append .CreateField("FirstField", dbText)
.Fields.Append .CreateField("SecondField", dbText)
End With
dbs.TableDefs.Append tdf 'remember, I don't want to
append
dbs.TableDefs.Refresh
Set rst1 = dbs.OpenRecordset(tdf, dbOpenDynaset)
With rst1
.AddNew
!FirstField = "black"
!SecondField = "dog"
.Update
.AddNew
!FirstField = "blue"
!SecondField = "bird"
.Update
End With
Set rst2 = dbs.OpenRecordset(tdf, dbOpenTable)
With rst2
.MoveLast
.MoveFirst
Do While Not .EOF
strSQL = "Select Phantom.FirstField,
Phantom.SecondField from Phantom;"
txtFirst = rst2!FirstField
txtSecond = rst2!SecondField
MsgBox txtFirst & " " & txtSecond
.MoveNext
Loop
.Close
End With
End Sub
I would like to create a table that exists only in memory
while the subroutine is running. I get hung up when it
comes time to refresh the table defs. What I've written
so far only works if I append the table. What am I
missing?
Sub PhantomTable()
Dim dbs As Database
Dim rst, rst1, rst2 As Recordset
Dim tdf As TableDef
Dim strSQL, txtFirst, txtSecond As String
Set dbs = OpenDatabase("C:\Working
Models\PhantomTable.mdb")
Set tdf = dbs.CreateTableDef("Phantom")
With tdf
.Fields.Append .CreateField("FirstField", dbText)
.Fields.Append .CreateField("SecondField", dbText)
End With
dbs.TableDefs.Append tdf 'remember, I don't want to
append
dbs.TableDefs.Refresh
Set rst1 = dbs.OpenRecordset(tdf, dbOpenDynaset)
With rst1
.AddNew
!FirstField = "black"
!SecondField = "dog"
.Update
.AddNew
!FirstField = "blue"
!SecondField = "bird"
.Update
End With
Set rst2 = dbs.OpenRecordset(tdf, dbOpenTable)
With rst2
.MoveLast
.MoveFirst
Do While Not .EOF
strSQL = "Select Phantom.FirstField,
Phantom.SecondField from Phantom;"
txtFirst = rst2!FirstField
txtSecond = rst2!SecondField
MsgBox txtFirst & " " & txtSecond
.MoveNext
Loop
.Close
End With
End Sub