VB高手帮帮忙
一个数据库管理程序:数据控件名为data1,3个命令按纽从左至右依次为增加、确定、取消。5个label框分别名为“编号、课时数、课时津贴、双师补助、合计金额”每个对应一个text框,按要求编写事件过程实现添加记录的功能。
补充:要简短一点的,只要能单击3个命令按钮能实现,能增加功能就好了.
答案:'晕倒,几百年没用 Data1了, 我这个代码刚好是楼主要的.mdb路径自己改
'添加 Command1(0)....Command1(6) Text1(0) Text1(1) Text1(2) Data1 与 Combo1
'希望可以帮助你
Option Explicit
Public datadisk As String, datapos As Integer, addupd As Integer, trecord As Integer, aa As String
Public oldpos As Integer, olddata As String, i As Integer, jj As Integer, midstr As String
Private Sub form_load()
If Right(App.Path, 1) <> "\" Then
datadisk = App.Path & "\"
Else
datadisk = App.Path
End If
Data1.DatabaseName = datadisk & "bwscale.mdb"
Data1.RecordSource = "bwcust"
Data1.Refresh
Data1.ReadOnly = False
Command1(0).Caption = "新 增"
Command1(1).Caption = "修 改"
Command1(2).Caption = "保 存"
Command1(3).Caption = "取 消"
Command1(4).Caption = "删 除"
Command1(5).Caption = "上 笔"
Command1(6).Caption = "下 笔"
End Sub
Private Sub Form_Activate()
trecord = 0
If Data1.Recordset.RecordCount > 0 Then
Combo1.Clear
Data1.Recordset.MoveFirst
Do While Not Data1.Recordset.EOF
If Data1.Recordset.Fields(0) <> "" Then
Combo1.AddItem Data1.Recordset.Fields(0)
trecord = trecord + 1
End If
If Not Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
End If
Loop
Combo1.Text = Combo1.List(0)
End If
If trecord > 0 Then
Data1.Recordset.MoveFirst
For i = 0 To 2
If Data1.Recordset.Fields(i) <> "" Then
Text1(i).Text = Trim(Data1.Recordset.Fields(i))
End If
Next i
End If
datapos = 0
oldpos = 0
addupd = 2
Call cominit
End Sub
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0 '新增
oldpos = datapos
inittext
For i = 0 To 6
Command1(i).Enabled = False
Next i
Command1(2).Enabled = True
Command1(3).Enabled = True
addupd = 1
Case 1 '修改
oldpos = datapos
For i = 0 To 6
Command1(i).Enabled = False
Next i
Command1(2).Enabled = True
Command1(3).Enabled = True
addupd = 2
Text1(0).SetFocus
Case 2 '保存
If addupd = 1 Or addupd = 2 Then
If addupd = 1 Then '新增
Data1.Recordset.AddNew
Else
Data1.Recordset.Edit
End If
Data1.Recordset.Fields(0) = Trim(Text1(0).Text)
Data1.Recordset.Fields(1) = Trim(Text1(1).Text)
Data1.Recordset.Fields(2) = Trim(Text1(2).Text)
Data1.Recordset.Update
Data1.Refresh
End If
Call cominit
If addupd = 1 Then
trecord = trecord + 1
Combo1.AddItem Text1(0).Text
End If
Case 3 '取消
Call cominit
If trecord > 0 Then
Data1.Recordset.MoveFirst
Data1.Recordset.Move (oldpos)
End If
Case 4 '删除
Data1.Recordset.Delete
trecord = trecord - 1
If trecord > 0 Then
If Not Data1.Recordset.EOF Then
Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
Data1.Recordset.MoveLast
datapos = trecord - 1
Else
datapos = datapos + 1
End If
Else
datapos = trecord - 1
End If
Data1.Refresh
Data1.Recordset.MoveFirst
Data1.Recordset.Move (datapos)
Else
inittext
End If
Call cominit
For i = 0 To Combo1.ListCount - 1
If Trim(Combo1.List(i)) = olddata Then
上一个:求VB常用函数?
下一个:求VB小软件一个