Dim a As String '定义字符串变量
a = MsgBox("您确实要修改这条数据吗?", vbYesNo)
If a = vbYes Then
'赋值给数据库字段
rs1.Fields("设备编号") = Text1(0).Text: rs1.Fields("设备型号") = Text1(1).Text
rs1.Fields("使用状态") = Text1(2).Text: rs1.Fields("是否损坏") = Combo1.Text
rs1.Update '更新记录集
Adodc1.Refresh
End If
Else
If Text1(0).Text = "" Then
MsgBox ("请输入设备编号!")
Exit Sub
End If
If Text1(1).Text = "" Then
MsgBox ("请输入设备型号!")
Exit Sub
End If
If Text1(2).Text = "" Then
MsgBox ("请输入使用状态!")
Exit Sub
End If
rs1.AddNew '添加包房信息
'赋值给数据库字段
rs1.Fields("设备编号") = Text1(0).Text: rs1.Fields("设备型号") = Text1(1).Text
rs1.Fields("使用状态") = Text1(2).Text: rs1.Fields("是否损坏") = Combo1.Text
rs1.Update '更新记录集
Adodc1.Refresh
MsgBox "成功保存!"
End If
Frame1.Visible = False '设置Frame1不可见
End Sub
Private Sub Form_Unload(Cancel As Integer)
Form1.Enabled = True
End Sub
Private Sub ComAdd_Click() '添加
Frame1.Visible = True 'frame1可见
Dim dm As Integer '定义一个整型变量
txtSQL = "select * from 设备状态信息 order by 设备编号"
Set rs1 = ESQL(txtSQL) '执行SQL语句
If rs1.RecordCount > 0 Then '当记录大于零时
If Not rs1.EOF Then rs1.MoveLast '如记录没到头,那么移到最后一条记录
If rs1.Fields("设备编号") <> "" Then '假如编号不等于空
dm = Trim(rs1.Fields("设备编号")) + 1 '赋值给dm变量
Text1(0).Text = Format(dm, "0000") '赋值给text1(0).text
End If
Else '否则
Text1(0).Text = "0001" '为text1(0).text设初值
End If
'清空数据
Text1(1).Text = ""
Text1(2).Text = ""
Text1(1).SetFocus 'text1(1)获得焦点
End Sub
Private Sub ComModify_Click() '允许修改数据
If Adodc1.Recordset.RecordCount > 0 Then '当记录大于零时
Frame1.Visible = True 'frame1可见
'赋值给Text1(i)等
If Adodc1.Recordset.Fields(0) <> "" Then Text1(0).Text = Trim(Adodc1.Recordset.Fields(i))
If Adodc1.Recordset.Fields(1) <> "" Then Text1(1).Text = Trim(Adodc1.Recordset.Fields(i))
If Adodc1.Recordset.Fields(2) <> "" Then Text1(2).Text = Trim(Adodc1.Recordset.Fields(i))
If Adodc1.Recordset.Fields("是否损坏") <> "" Then Combo1.Text = Trim(Adodc1.Recordset.Fields("是否损坏"))
Else
MsgBox "没有要修改的记录,请核对!"
End If
End Sub
Private Sub ComDelete_Click() '删除包房信息
Frame1.Visible = False 'frame1不可见
On Error Resume Next
Adodc1.Recordset.Delete '删除记录
Adodc1.Refresh '刷新记录
End Sub
Private Sub ComSave_Click()
txtSQL = "select * from 设备状态信息 where 设备编号='" & Trim(Text1(0).Text) & "'order by 设备编号"
Set rs1 = ESQL(txtSQL)
If rs1.RecordCount > 0 Then '当记录大于零时
Dim a As String '定义字符串变量
a = MsgBox("您确实要修改这条数据吗?", vbYesNo)
If a = vbYes Then
If Text1(0).Text = "" Then
MsgBox ("请输入设备编号!")
Exit Sub
End If
'赋值给数据库字段
rs1.Fields("设备编号") = Text1(0).Text: rs1.Fields("设备型号") = Text1(1).Text
rs1.Fields("使用状态") = Text1(2).Text: rs1.Fields("是否损坏") = Combo1.Text
rs1.Update '更新记录集
Adodc1.Refresh
End If
Else
If Text1(0).Text = "" Then
MsgBox ("请输入设备编号!")
Exit Sub
End If
If Text1(1).Text = "" Then
MsgBox ("请输入设备型号!")
Exit Sub
End If
If Text1(2).Text = "" Then
MsgBox ("请输入使用状态!")
Exit Sub
End If
rs1.AddNew
'赋值给数据库字段
rs1.Fields("设备编号") = Text1(0).Text: rs1.Fields("设备型号") = Text1(1).Text
rs1.Fields("使用状态") = Text1(2).Text: rs1.Fields("是否损坏") = Combo1.Text
rs1.Update '更新记录集
Adodc1.Refresh
MsgBox "状态信息已成功保存!"
End If
Frame1.Visible = False '设置Frame1不可见
End Sub
Private Sub Comfind_Click() '查询
Select Case Combo4.Text
Case Is = "like"
Adodc1.RecordSource = "select * from 设备状态信息 where (设备状态信息." & Combo3.Text & " like +'%'+ '" + Text2.Text + "'+'%') order by 设备编号"
Adodc1.Refresh
Case Is = "="
Adodc1.RecordSource = "select * from 设备状态信息 where (设备状态信息." & Combo3.Text & " = '" + Text2.Text + "') order by 设备编号"
Adodc1.Refresh
End Select
End Sub
Private Sub ComEsc_Click() '取消操作
Frame1.Visible = False
End Sub
Private Sub ComExit_Click()
Unload Me
Form1.Enabled = True
End Sub
Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If Index = 12 Then KeyAscii = valiText(KeyAscii, "0123456789." & Chr(13), True)
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then ComFind.SetFocus
End Sub
若图片无法显示请联系QQ752018766,本论文免费,转发请注明源于www.751com.cn图6.10 查询使用单位信息
图6.11添加使用单位信息
图6.12修改使用单位信息
图6.13删除使用单位信息
Dim i As Integer '定义整数变量,表示字段编号和数组编号
Dim rs1 As New ADODB.Recordset '定义数据集对象
Dim txtSQL As String '定义一个字符串变量
Private Sub Form_Load()
'添加查询内容列表
Combo3.AddItem ("单位名称"): Combo3.AddItem ("设备编号")
Combo3.ListIndex = 0
'添加查询条件列表
Combo4.AddItem ("like"): Combo4.AddItem ("=")
Combo4.ListIndex = 0
Adodc1.RecordSource = "select * from 使用单位信息 order by 单位编号"
Adodc1.Refresh
End Sub
Private Sub Form_Unload(Cancel As Integer)
Form1.Enabled = True
End Sub
Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
Select Case Index
Case Is = Index
If KeyCode = vbKeyReturn And Index >= 1 And Index < 5 Then Text1(Index + 1).SetFocus '回车获得焦点
If KeyCode = vbKeyReturn And Index >= 9 And Index < 12 Then Text1(Index + 1).SetFocus
If KeyCode = vbKeyReturn And Index = 12 Then ComSave.SetFocus
End Select
End Sub
Private Sub ComAdd_Click() '添加
Frame1.Visible = True 'frame1可见
Dim dm As Integer '定义一个整型变量
txtSQL = "select * from 使用单位信息 order by 单位编号"
Set rs1 = ESQL(txtSQL) '执行SQL语句
If rs1.RecordCount > 0 Then '当记录大于零时
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>