alfboy50
10-14-2004, 11:14 AM
Ok i am having another problem. As many of you know I am a teacher and I am creating a program that will allow me to make virtual tests. I have a table in Access called Student that will hold the records of the test that are taken. This table will hold the login name, fullname, checkboxes for the test so I can tell who took what test, and a fields that will hold the percent scored on each test. Right now I only have the login field and fullname fields in Access. I want the program to add two fields to the Student table each time I create a test. I don't care if the fields names are the same or different as long as one is a checkbox and the other is a number. This my code
Dim OpenTable As Recordset
Public TableName As String
Dim Table As Recordset
Private Sub cmdOk_Click()
Set DataB = OpenDatabase("Z:\TestPro\Login.mdb")
Dim tdef As TableDef
Dim tdef2 As TableDef
' Create a new TableDef object.
Set tdef = DataB.CreateTableDef(txtTestName.Text)
TableName = txtTestName.Text
tdef.Fields.Append tdef.CreateField("Question#", dbMemo, 2)
tdef.Fields.Append tdef.CreateField("Question", dbMemo, 75)
tdef.Fields.Append tdef.CreateField("AAnswer", dbMemo, 25)
tdef.Fields.Append tdef.CreateField("BAnswer", dbMemo, 25)
tdef.Fields.Append tdef.CreateField("CAnswer", dbMemo, 25)
tdef.Fields.Append tdef.CreateField("DAnswer", dbMemo, 25)
tdef.Fields.Append tdef.CreateField("CorrectAns", dbMemo, 1)
tdef.Fields.Append tdef.CreateField("PointValue", dbLong, 2)
DataB.TableDefs.Append tdef
Set tdef2 = DataB.CreateTableDef("Student")
tdef2.Fields.Append tdef2.CreateField("TableName", dbBoolean)
tdef2.Fields.Append tdef2.CreateField("TableName", dbLong, 2)
Set Test = DataB.OpenRecordset("TestNames")
Test.AddNew
Test.Fields("TestName").Value = TableName
MsgBox "Ok"
Test.Update
frmQuestion2.Show
As you can probably tell, I have a lot going on in this form. I am having the test table created and I am adding the testname to the testnames table. I am getting no errors with this code but it isn't writing to the Student table. I want it to be though. Can someone please help with how to add two fields in that table. I am using VB 6.0 with the DAO code and I am connecting it to an Access 2002. Thanks ahead of time.
Dim OpenTable As Recordset
Public TableName As String
Dim Table As Recordset
Private Sub cmdOk_Click()
Set DataB = OpenDatabase("Z:\TestPro\Login.mdb")
Dim tdef As TableDef
Dim tdef2 As TableDef
' Create a new TableDef object.
Set tdef = DataB.CreateTableDef(txtTestName.Text)
TableName = txtTestName.Text
tdef.Fields.Append tdef.CreateField("Question#", dbMemo, 2)
tdef.Fields.Append tdef.CreateField("Question", dbMemo, 75)
tdef.Fields.Append tdef.CreateField("AAnswer", dbMemo, 25)
tdef.Fields.Append tdef.CreateField("BAnswer", dbMemo, 25)
tdef.Fields.Append tdef.CreateField("CAnswer", dbMemo, 25)
tdef.Fields.Append tdef.CreateField("DAnswer", dbMemo, 25)
tdef.Fields.Append tdef.CreateField("CorrectAns", dbMemo, 1)
tdef.Fields.Append tdef.CreateField("PointValue", dbLong, 2)
DataB.TableDefs.Append tdef
Set tdef2 = DataB.CreateTableDef("Student")
tdef2.Fields.Append tdef2.CreateField("TableName", dbBoolean)
tdef2.Fields.Append tdef2.CreateField("TableName", dbLong, 2)
Set Test = DataB.OpenRecordset("TestNames")
Test.AddNew
Test.Fields("TestName").Value = TableName
MsgBox "Ok"
Test.Update
frmQuestion2.Show
As you can probably tell, I have a lot going on in this form. I am having the test table created and I am adding the testname to the testnames table. I am getting no errors with this code but it isn't writing to the Student table. I want it to be though. Can someone please help with how to add two fields in that table. I am using VB 6.0 with the DAO code and I am connecting it to an Access 2002. Thanks ahead of time.