具体地说,就是新增按钮(Command1)功能不正常:表现为:只能在VB里输入一次,保存后关闭VB,重新打开VB或者直接打开ACCESS,都能看见该记录;
但输入第二个记录,保存后关闭VB,打开ACCESS,只能看见第一个记录,第二个仍然看不见,再打开VB,也同样看不见第二个记录!
删除按钮等其他按钮功能正常!
但是,反过来,在ACCESS里编辑的话,就可以在VB程序里正常读取!
一个ACCESS2000的MDB文件:DB3。MDB附带两个子表TS(msg、addrecord)、QQ(msg2、addrecord2)
本来两个子窗体代码的msg、addrecord定义完全一样,没有用2来区别下,因为调试不正常,于是用2区别了下,但无效!
两个子窗体的保存更新代码如下:QQ更新代码如下:(TS同,略)
Private Sub Data1_Validate(Action As Integer, Save As Integer)
Static addrecord2 As Boolean
Dim msg2
Select Case Action
Case 1, 2, 3, 4, 5, 11
If Save Then
msg2 = MsgBox("数据需要更新么?", vbYesNo)
If msg2 = vbNo Then
Save = 0
If addrecord2 Then
Data1.UpdateControls
End If
End If
End If
If Action = 5 Then addrecord2 = True Else addrecord2 = False
Command2.Enabled = True
End Select
End Sub
新增按钮(Command1)代码如下(QQ、TS完全相同):
Private Sub Command1_Click()
If Command1.Caption = "新增" Then
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Command6.Enabled = False
Command7.Enabled = False
Command1.Caption = "确定"
Command2.Caption = "放弃"
If Data1.Recordset.RecordCount > 0 Then
Data1.Recordset.MoveLast
End If
Data1.Recordset.AddNew
Text1.SetFocus
Else
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
Command6.Enabled = True
Command7.Enabled = True
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text10.Text = ""
Text11.Text = ""
Text12.Text = ""
Text13.Text = ""
Text14.Text = ""
Text15.Text = ""
Command1.Caption = "新增"
Command2.Caption = "删除"
Command1.SetFocus
End If
End Sub