在照书练习中出现“对象变量或with块变量未设置”错误 是用DAO方法连接的数据库,原理是在form1中将data1和msflexgrid控件绑定,单击msflexgrid控件弹出form2,在form2中进行数据修改,刚学习vb不久,请多帮助
源码如下:
form1
Private Sub Form_Load()
Text1.Text = Form1.Data1.Recordset.Fields("教师编号")
Text2.Text = Form1.Data1.Recordset.Fields("姓名")
Text3.Text = Form1.Data1.Recordset.Fields("性别")
Text4.Text = Form1.Data1.Recordset.Fields("出生日期")
Text5.Text = Form1.Data1.Recordset.Fields("职称")
Text6.Text = Form1.Data1.Recordset.Fields("单位")
Text7.Text = Form1.Data1.Recordset.Fields("工资")
End Sub
Private Sub MSFlexGrid1_Click()
Data1.Recordset.AbsolutePosition = MSFlexGrid1.Row - 1
Form2.Show vbModal
End Sub
form2:
Private Sub Command1_Click()
Form1.Data1.Recordset.Edit
Form1.Data1.Recordset.Fields("教师编号") = Text1.Text
Form1.Data1.Recordset.Fields("姓名") = Text2.Text
Form1.Data1.Recordset.Fields("性别") = Text3.Text
Form1.Data1.Recordset.Fields("出生日期") = Text4.Text
Form1.Data1.Recordset.Fields("职称") = Text5.Text
Form1.Data1.Recordset.Fields("单位") = Text6.Text
Form1.Data1.Recordset.Fields("工资") = Text7.Text
Form1.Data1.Recordset.Update
Form1.Data1.Refresh
End Sub
Private Sub Command2_Click()
Unload Form2
End Sub