Private Sub mnuEmpRemove_Click()
Dim rs As ADODB.Recordset
Dim str1 As String
str1 = InputBox("请输入要删除的员工的编号", "删除员工")
Set rs = g_DBCon.Execute("select * from EmpList where ENumber='" & str1 & "'")
If Not (rs.EOF And rs.BOF) Then
Set rs = Nothing
g_DBCon.Execute ("delete from EmpList where ENumber='" & str1 & "'")
MsgBox "编号为" & str1 & "的员工信息已经被删除... ", vbInformation, "删除员工信息"
Else
MsgBox "编号为" & str1 & "的员工信息不存在", vbInformation, "编号错误"
End If
End Sub
这是删除员工信息的代码,当从对话框输入的编号与记录中匹配时就删除该条记录,否则
提示该记录不存在,现在有一个问题:当点击inputbox的取消按钮时也会弹出else后的msgbox,
要想点击取消时直接关闭而不弹出msgbox,该怎么做呢?
Dim rs As ADODB.Recordset
Dim str1 As String
str1 = InputBox("请输入要删除的员工的编号", "删除员工")
Set rs = g_DBCon.Execute("select * from EmpList where ENumber='" & str1 & "'")
If Not (rs.EOF And rs.BOF) Then
Set rs = Nothing
g_DBCon.Execute ("delete from EmpList where ENumber='" & str1 & "'")
MsgBox "编号为" & str1 & "的员工信息已经被删除... ", vbInformation, "删除员工信息"
Else
MsgBox "编号为" & str1 & "的员工信息不存在", vbInformation, "编号错误"
End If
End Sub
这是删除员工信息的代码,当从对话框输入的编号与记录中匹配时就删除该条记录,否则
提示该记录不存在,现在有一个问题:当点击inputbox的取消按钮时也会弹出else后的msgbox,
要想点击取消时直接关闭而不弹出msgbox,该怎么做呢?
Private Sub mnuEmpRemove_Click()
Dim rs As ADODB.Recordset
Dim str1 As String
str1 = InputBox("请输入要删除的员工的编号", "删除员工")
if str1<>"" then '首先判断有没有点取消按钮
Set rs = g_DBCon.Execute("select * from EmpList where ENumber='" & str1 & "'")
If Not (rs.EOF And rs.BOF) Then
Set rs = Nothing
g_DBCon.Execute ("delete from EmpList where ENumber='" & str1 & "'")
MsgBox "编号为" & str1 & "的员工信息已经被删除... ", vbInformation, "删除员工信息"
Else
MsgBox "编号为" & str1 & "的员工信息不存在", vbInformation, "编号错误"
End If
end if
End Sub
else
if str1="" then '说明是输入空字串,点确认
else
end if
end if
Dim rs As ADODB.Recordset
Dim str1 As String
str1 = InputBox("请输入要删除的员工的编号", "删除员工")
If str1="" Then goto handler:
Set rs = g_DBCon.Execute("select * from EmpList where ENumber='" & str1 & "'")
If Not (rs.EOF And rs.BOF) Then
Set rs = Nothing
g_DBCon.Execute ("delete from EmpList where ENumber='" & str1 & "'")
MsgBox "编号为" & str1 & "的员工信息已经被删除... ", vbInformation, "删除员工信息"
Else
MsgBox "编号为" & str1 & "的员工信息不存在", vbInformation, "编号错误"
End If
handler:
End Sub
不好意思按楼上的修改后还是老样子
如果你点了"取消",这时input返回的是"一个空串"",利用goto跳到End Sub前,随后退出!
就是If str1="" then goto
你再试下
Private Sub ShowData() '显示员工信息的函数
Dim intindex As Long
TxtCode.Text = rs.Fields("ENumber").Value
TxtName.Text = rs.Fields("EName").Value
TxtAge.Text = rs.Fields("EAge").Value
CmbDate.Text = rs.Fields("EDate").Value
TxtAddress.Text = rs.Fields("EAddress").Value
For intindex = 0 To CmbDate.ListCount - 1
'模式为2-DropDown List的组合框不能直接通过文本赋值
'只能通过指定ListIndex值来选择某个项
If CmbDate.List(intindex) = Trim(rs.Fields("EDate").Value) Then
CmbDate.ListIndex = intindex
End If
Next intindex
End SubPrivate Sub cmdDelete_Click() '删除员工信息
If MsgBox("确认删除该员工记录信息吗?", vbQuestion + vbYesNo, "删除员工信息") = vbYes Then
rs.Delete
Call cmdNext_Click
End If
End Sub
当点击删除按钮后该员工记录仍然存在,不知是什么原因?(在模块中已经定义了recordset和
connection对象)