📄 gongmessage_frm.frm
字号:
Top = 120
Width = 480
End
End
Attribute VB_Name = "gongmessage_frm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'定义书签,用来记载当前记录位置
Dim mybookmark As Variant
' 看是否修改记录
Dim mcclean As Boolean
Private Sub Command5_Click()
On Error Resume Next
Ado.Recordset.Close
Ado.Recordset.Open "select * from db1 "
If Ado.Recordset.EOF Then
MsgBox "你所输入的车号还没登记"
Else
'调用显示数据的函数
Call viewdata1
End If
End Sub
Private Sub Command6_Click()
On Error Resume Next
Ado.Recordset.MovePrevious
If Ado.Recordset.BOF Then
'移动到数据集的最后一条记录
Ado.Recordset.MoveLast
End If
'调用显示数据的函数
Call viewdata1
End Sub
Private Sub Command7_Click()
If Ado.Recordset.EOF Then
'移动到数据集的第一条记录
On Error Resume Next
Ado.Recordset.MoveFirst
Else
On Error Resume Next
Ado.Recordset.MoveNext
If Ado.Recordset.EOF Then
Ado.Recordset.MoveFirst
End If
End If
Call viewdata1
End Sub
Private Sub Command8_Click()
On Error Resume Next
Ado.Recordset.MoveLast
Call viewdata1
End Sub
Public Sub viewdata1()
Text1.Text = Ado.Recordset.Fields("车号").value
Text2.Text = Ado.Recordset.Fields("发车时间").value
Text3.Text = Ado.Recordset.Fields("收车时间").value
Text4.Text = Ado.Recordset.Fields("起点站").value
Text5.Text = Ado.Recordset.Fields("终点站").value
Text6.Text = Ado.Recordset.Fields("停靠站").value
End Sub
Private Sub Form_Load()
Ado.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb;Persist Security Info=False"
Ado.CommandType = adCmdText
Ado.RecordSource = "select * from db1"
Ado.Refresh
If Not Ado.Recordset.BOF Or Not Ado.Recordset.EOF Then
Ado.Recordset.MoveFirst
Call viewdata
'记下当前记录的位置
mybookmark = Ado.Recordset.Bookmark
Else
MsgBox "数据库数据全部删除,请添加数据!"
End If
'给标志赋初值
mcclean = True
'使个文本框失效
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
End Sub
Private Sub Command1_Click()
mcclean = False
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = True
Text4.Enabled = True
Text5.Enabled = True
Text6.Enabled = True
Command4.Enabled = False
End Sub
Public Sub viewdata()
Text1.Text = Ado.Recordset.Fields(0)
Text2.Text = Ado.Recordset.Fields(4)
Text3.Text = Ado.Recordset.Fields(5)
Text4.Text = Ado.Recordset.Fields(1)
Text5.Text = Ado.Recordset.Fields(2)
Text6.Text = Ado.Recordset.Fields(3)
End Sub
Private Sub Command2_Click()
Command4.Enabled = True
'是否处于修改状态
If mcclean Then
MsgBox "请先修改公交车信息", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
'车号是否为空
If Not testtxt(Text1.Text) Then
MsgBox "请输入车号", vbOKOnly + vbExclamation, "警告"
On Error Resume Next
Text1.SetFocus
Exit Sub
End If
'发车时间是否为空
If Not testtxt(Text2.Text) Then
MsgBox "请输入发车时间", vbOKOnly + vbExclamation, "警告"
Text2.SetFocus
Exit Sub
End If
' 收车时间是否为空
If Not testtxt(Text3.Text) Then
MsgBox "请输入收车时间", vbOKOnly + vbExclamation, "警告"
Text3.SetFocus
Exit Sub
End If
'起点站是否为空
If Not testtxt(Text4.Text) Then
MsgBox "请输入起点站", vbOKOnly + vbExclamation, "警告"
Text4.SetFocus
Exit Sub
End If
'终点站是否为空
If Not testtxt(Text5.Text) Then
MsgBox "请输入终点站", vbOKOnly + vbExclamation, "警告"
Text5.SetFocus
Exit Sub
End If
'停靠站是否为空
If Not testtxt(Text6.Text) Then
MsgBox "请输入停靠站", vbOKOnly + vbExclamation, "警告"
Text6.SetFocus
Exit Sub
End If
'看是否有重复记录
Ado.Recordset.Close
Ado.Recordset.Open "select * from db1 where 车号='" & Trim(Text1.Text) & " '"
If Ado.Recordset.EOF = False Then
MsgBox "车号重复!", vbOKOnly + vbExclamation, "警告"
Ado.Recordset.Close
On Error Resume Next
Text1.SetFocus
Else
Ado.Recordset.Close
End If
Ado.Recordset.Open "select * from db1"
Ado.Recordset.AddNew
Ado.Recordset.Fields(0) = Trim(Text1.Text)
Ado.Recordset.Fields(4) = Trim(Text2.Text)
Ado.Recordset.Fields(2) = Trim(Text5.Text)
Ado.Recordset.Fields(1) = Trim(Text4.Text)
Ado.Recordset.Fields(3) = Trim(Text6.Text)
Ado.Recordset.Fields(5) = Trim(Text3.Text)
Ado.Recordset.Update
MsgBox "修改公交车信息成功!", vbOKOnly + vbExclamation, "修改公交车修息"
Ado.Recordset.Bookmark = mybookmark
Call viewdata
'使各个文本框有效
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
mcclean = True
End Sub
Private Sub Command3_Click()
'看是否处于修改状态
If Not mcclean Then
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
'回到开始记录位置
On Error Resume Next
Ado.Recordset.Bookmark = mybookmark
Call viewdata
Else
MsgBox "什么都没有修改,请不要取消!", vbOKOnly + vbExclamation, "警告"
End If
End Sub
Private Sub Command4_Click()
'记下当前记录位置
On Error Resume Next
mybookmark = Ado.Recordset.Bookmark
'提示是否删除
str2$ = MsgBox("是否删除当前记录?", vbOKCancel, "删除当前记录")
'看按钮类型
If str2$ = vbOK Then
'移动到数据集下一条记录
Ado.Recordset.MoveNext
'看数据集对像是否为空
If Ado.Recordset.EOF Then
'移动到数据集的第一条记录
Ado.Recordset.MoveFirst
'记载当前记录的位置
mybookmark = Ado.Recordset.Bookmark
'移动到数据集的最后一条记录
Ado.Recordset.MoveLast
'删除记录
Ado.Recordset.Delete
If Ado.Recordset.BOF Or Ado.Recordset.EOF Then
Ado.Recordset.Bookmark = mybookmark
Call viewdata
Else
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End If
Else
'记录当前位置
mybookmark = Ado.Recordset.Bookmark
Ado.Recordset.MovePrevious
On Error Resume Next
Ado.Recordset.Delete
If Ado.Recordset.BOF Then
If Ado.Recordset.EOF Then
MsgBox "数据库数据全部删除,请添加数据!"
Exit Sub
Else
Ado.Recordset.MoveNext
mybookmark = Ado.Recordset.Bookmark
End If
Else
Ado.Recordset.MoveLast
mybookmark = Ado.Recordset.Bookmark
End If
'回到原来的位置
If Not Ado.Recordset.BOF Or Not Ado.Recordset.EOF Then
Ado.Recordset.Bookmark = mybookmark
Call viewdata
Else
MsgBox "数据库数据全部删除,请添加数据!"
End If
End If
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -