Article ID: 140898
Article Last Modified on 3/2/2005
Dim rs1 As Recordset
Dim rs2 As Recordset
Dim db As Database
Dim td As TableDef
Dim fl As Field
Private Sub Command1_Click()
Set Data1.Recordset = rs2
Set Data1.Recordset = rs1
End Sub
Private Sub Form_Load()
Dim x As Integer, y As Integer
'If the database does not exist, create the database
If Dir("C:\TEST.MDB") = "" Then
Set db = CreateDatabase("C:\test.mdb", dbLangGeneral)
'Create the table in the database
Set td = db.CreateTableDef("TABLE1")
'Create the fields in the database
For x = 1 To 26
Set fl = td.CreateField("Field " & CStr(x), dbInteger)
td.Fields.Append fl
Next x
db.TableDefs.Append td
'Add records to the database through a recordset
Set rs1 = db.OpenRecordset("TABLE1", dbOpenTable)
For y = 1 To 11 'For each row
rs1.AddNew 'Add a new record
For x = 1 To 26 'For each cell in the record
rs1("Field " & CStr(x)) = x 'Add a number
Next x
rs1.Update
Next y
'Close both the recordset and database
rs1.Close
db.Close
End If
'Open the database and create the recordsets
Set db = OpenDatabase("C:\TEST.MDB")
Set rs1 = db.OpenRecordset("Select * From TABLE1")
Set rs2 = db.OpenRecordset("Select * From TABLE1")
Set Data1.Recordset = rs1
End Sub
Additional query words: 4.00 vb4win vb432 buglist4.00
Keywords: kbbug KB140898