"Private Sub Command1_Click()
Unload Me
Form1.Show
End Sub"
返回主窗体时,再打开该子窗体,却出现提示:
“实时错误,对象已打开,不允许操作!”
代码错哪呢?
再改为:
“Form1.Show
Me.Hide”
还是出现同样的错误提示!
主窗体代码:
Private Sub cx_Click()
Form3.Show
Me.Hide
End Sub
Private Sub exit_Click()
End
End Sub
Private Sub Form_Load()
Form2.Show
Form1.Hide
End Sub
Private Sub qqxxbj_Click()
Unload Me
qqbj.Show
End Sub
Private Sub qqxxcx_Click()
qqcx.Show
Me.Hide
End Sub
其中一个子窗体(qqbj)代码:
Option Explicit
Private Conn As ADODB.Connection
Private Rst As New ADODB.Recordset
Private Sub CmdAdd_Click()
Text1.SetFocus
CmdDelete.Enabled = False
CmdPrevious.Enabled = False
CmdNext.Enabled = False
CmdFirst.Enabled = False
CmdLast.Enabled = False
'Set Rst = CreateObject("ADODB.Recordset")
If (Rst.State = adStateOpen) Then
Rst.Close
End If
Rst.CursorLocation = adUseClient
Rst.Open "Select * From 亲戚信息", Conn, adOpenKeyset, adLockPessimistic
Rst.AddNew
Rst.Fields("姓名").Value = Text1.Text
Rst.Fields("单位名称").Value = Text2.Text
Rst.Fields("办公电话").Value = Text3.Text
Rst.Fields("办公电话二").Value = Text4.Text
Rst.Fields("手机").Value = Text5.Text
Rst.Fields("手机二").Value = Text6.Text
Rst.Fields("宅电").Value = Text7.Text
Rst.Fields("宅电二").Value = Text8.Text
Rst.Fields("电子邮箱").Value = Text9.Text
Rst.Fields("电子邮箱二").Value = Text10.Text
Rst.Fields("QQ号").Value = Text11.Text
Rst.Fields("QQ号二").Value = Text12.Text
Rst.Fields("地址").Value = Text13.Text
Rst.Fields("邮政编码").Value = Text14.Text
Rst.Fields("其他").Value = Text15.Text
Rst.Update
MsgBox "添加成功"
CmdDelete.Enabled = True
CmdPrevious.Enabled = True
CmdNext.Enabled = True
CmdFirst.Enabled = True
CmdLast.Enabled = True
End Sub
Private Sub CmdDelete_Click()
CmdAdd.Enabled = False
CmdPrevious.Enabled = False
CmdNext.Enabled = False
CmdFirst.Enabled = False
CmdLast.Enabled = False
'Rst.CursorLocation = adUseClient
If MsgBox("要删除吗?", vbExclamation + vbYesNo) = vbYes Then
Rst.Delete
End If
MsgBox "删除成功"
CmdAdd.Enabled = True
CmdPrevious.Enabled = True
CmdNext.Enabled = True
CmdFirst.Enabled = True
CmdLast.Enabled = True
End Sub
Private Sub CmdFirst_Click()
Rst.MoveFirst
Text1.Text = Rst.Fields("姓名").Value
Text2.Text = Rst.Fields("单位名称").Value
Text3.Text = Rst.Fields("办公电话").Value
Text4.Text = Rst.Fields("办公电话二").Value
Text5.Text = Rst.Fields("手机").Value
Text6.Text = Rst.Fields("手机二").Value
Text7.Text = Rst.Fields("宅电").Value
Text8.Text = Rst.Fields("宅电二").Value
Text9.Text = Rst.Fields("电子邮箱").Value
Text10.Text = Rst.Fields("电子邮箱二").Value
Text11.Text = Rst.Fields("QQ号").Value
Text12.Text = Rst.Fields("QQ号二").Value
Text13.Text = Rst.Fields("地址").Value
Text14.Text = Rst.Fields("邮政编码").Value
Text15.Text = Rst.Fields("其他").Value
End Sub
Private Sub CmdLast_Click()
Rst.MoveLast
Text1.Text = Rst.Fields("姓名").Value
Text2.Text = Rst.Fields("单位名称").Value
Text3.Text = Rst.Fields("办公电话").Value
Text4.Text = Rst.Fields("办公电话二").Value
Text5.Text = Rst.Fields("手机").Value
Text6.Text = Rst.Fields("手机二").Value
Text7.Text = Rst.Fields("宅电").Value
Text8.Text = Rst.Fields("宅电二").Value
Text9.Text = Rst.Fields("电子邮箱").Value
Text10.Text = Rst.Fields("电子邮箱二").Value
Text11.Text = Rst.Fields("QQ号").Value
Text12.Text = Rst.Fields("QQ号二").Value
Text13.Text = Rst.Fields("地址").Value
Text14.Text = Rst.Fields("邮政编码").Value
Text15.Text = Rst.Fields("其他").Value
End Sub
Private Sub CmdNext_Click()
If (Not Rst.EOF) Then
Rst.MoveNext
If (Not Rst.EOF) Then
Text1.Text = Rst.Fields("姓名").Value
Text2.Text = Rst.Fields("单位名称").Value
Text3.Text = Rst.Fields("办公电话").Value
Text4.Text = Rst.Fields("办公电话二").Value
Text5.Text = Rst.Fields("手机").Value
Text6.Text = Rst.Fields("手机二").Value
Text7.Text = Rst.Fields("宅电").Value
Text8.Text = Rst.Fields("宅电二").Value
Text9.Text = Rst.Fields("电子邮箱").Value
Text10.Text = Rst.Fields("电子邮箱二").Value
Text11.Text = Rst.Fields("QQ号").Value
Text12.Text = Rst.Fields("QQ号二").Value
Text13.Text = Rst.Fields("地址").Value
Text14.Text = Rst.Fields("邮政编码").Value
Text15.Text = Rst.Fields("其他").Value
Else
Rst.MoveLast
Text1.Text = Rst.Fields("姓名").Value
Text2.Text = Rst.Fields("单位名称").Value
Text3.Text = Rst.Fields("办公电话").Value
Text4.Text = Rst.Fields("办公电话二").Value
Text5.Text = Rst.Fields("手机").Value
Text6.Text = Rst.Fields("手机二").Value
Text7.Text = Rst.Fields("宅电").Value
Text8.Text = Rst.Fields("宅电二").Value
Text9.Text = Rst.Fields("电子邮箱").Value
Text10.Text = Rst.Fields("电子邮箱二").Value
Text11.Text = Rst.Fields("QQ号").Value
Text12.Text = Rst.Fields("QQ号二").Value
Text13.Text = Rst.Fields("地址").Value
Text14.Text = Rst.Fields("邮政编码").Value
Text15.Text = Rst.Fields("其他").Value
MsgBox "这是最后一条记录!"
End If
End If
End Sub
Private Sub CmdPrevious_Click()
If (Not Rst.BOF) Then
Rst.MovePrevious
If (Not Rst.BOF) Then
Text1.Text = Rst.Fields("姓名").Value
Text2.Text = Rst.Fields("单位名称").Value
Text3.Text = Rst.Fields("办公电话").Value
Text4.Text = Rst.Fields("办公电话二").Value
Text5.Text = Rst.Fields("手机").Value
Text6.Text = Rst.Fields("手机二").Value
Text7.Text = Rst.Fields("宅电").Value
Text8.Text = Rst.Fields("宅电二").Value
Text9.Text = Rst.Fields("电子邮箱").Value
Text10.Text = Rst.Fields("电子邮箱二").Value
Text11.Text = Rst.Fields("QQ号").Value
Text12.Text = Rst.Fields("QQ号二").Value
Text13.Text = Rst.Fields("地址").Value
Text14.Text = Rst.Fields("邮政编码").Value
Text15.Text = Rst.Fields("其他").Value
Else
Rst.MoveFirst
Text1.Text = Rst.Fields("姓名").Value
Text2.Text = Rst.Fields("单位名称").Value
Text3.Text = Rst.Fields("办公电话").Value
Text4.Text = Rst.Fields("办公电话二").Value
Text5.Text = Rst.Fields("手机").Value
Text6.Text = Rst.Fields("手机二").Value
Text7.Text = Rst.Fields("宅电").Value
Text8.Text = Rst.Fields("宅电二").Value
Text9.Text = Rst.Fields("电子邮箱").Value
Text10.Text = Rst.Fields("电子邮箱二").Value
Text11.Text = Rst.Fields("QQ号").Value
Text12.Text = Rst.Fields("QQ号二").Value
Text13.Text = Rst.Fields("地址").Value
Text14.Text = Rst.Fields("邮政编码").Value
Text15.Text = Rst.Fields("其他").Value
MsgBox "这是第一条记录!"
End If
End If
End Sub
Private Sub Command1_Click()
Unload Me
Form1.Show
End Sub
Private Sub Form_Load()
Dim ConString As String
ConString = "Provider=Microsoft.Jet.OleDb.4.0;Persist Security Info = False;" _
& "Data Source =" & App.Path & "\db3.mdb"
Set Conn = CreateObject("ADODB.Connection")
With Conn
.ConnectionString = ConString
.Open
End With
Rst.CursorLocation = adUseClient
Rst.Open "Select * From 亲戚信息", Conn, adOpenKeyset, adLockPessimistic, adCmdText
End Sub