图片1 |
Sub p_abc() RS.Open " Select 姓名,职务,单位From A05_start Order By id", mConn, adOpenStatic Dim iSize, iNo As Long Dim Lname As String iNo = RS.RecordCount If iNo = 0 Then MsgBox "数据库中的数据项不能为空,请重新设置", vbOKOnly, "信息提示" Exit Sub End If Do While Not RS.EOF iSize = 0 iSize = Len(RS.Fields("姓名")) Lname = RS.Fields("姓名") lstFields.AddItem Lname + Space(2) + RS.Fields("单位") + RS.Fields("职务") RS.MoveNext Lname = "" Loop lstFields.ListIndex = -1 RS.Close End Sub |
Private Sub lstFields_ItemCheck(Item As Integer) '现场采集的过程 P = P + 1 '获取总次数 A_name(P) = Mid(lstFields.List(lstFields.ListIndex), 1, 3) '获取姓名 A_No(P) = lstFields.ListIndex '获取序号 A_TF(P) = lstFields.Selected(lstFields.ListIndex) '获取逻辑值 If A_TF(P) = "True" Then '获取有效的点击次数 P1 = P1 + 1 Else P1 = P1 - 1 End If 'End Sub |
Private Sub Command2_Click() Dim P_No, lNo As Integer Dim P_name As String …… '此处略掉部分代码,它们主要有: ①.判断身份证号(旧15)位或(新18)位 ②.判断[身份证号]的位数有误的提示 ③.判断[满10票为有效投票]的提示 RS.Open " Select * From A05_piao Where 身份='" & Text1.Text & "' Order By id", mConn, adOpenStatic lNo = 0 lNo = RS.RecordCount RS.Close If lNo > 0 Then MsgBox "对不起,您已经投过票,谢谢合作!!!", vbOKOnly, " > 操作信息提示 <" Text1.SetFocus Exit Sub End If For J = 1 To P '根据现场采集总次数,将数据插入表2 If A_No(J) >= 0 Then P_name = A_name(J) If A_TF(J) = "True" Then P_No = 1 '首此点击为 “勾”时为:1 Else P_No = -1 '原已点后去掉“勾”时为:-1 End If End If mConn.Execute "Insert Into A05_piao (身份,序号,姓名,票数) VALUES ('" & Text1.Text & "'," & A_No(J) & ",'" & A_name(J) & "'," & P_No & ")" Next J '--更新A05_start表1的内容 '--V_sum1为视图文件其格式:Select 姓名 Sum(票数) AS "票数" From A05_Piao Where flag is Null GROUP By 姓名 mConn.Execute " Update A05_start Set A05_start.票数 = A05_start.票数 + V_sum1.票数 From A05_start,v_sum1 Where A05_start.姓名 = V_sum1.姓名 " mConn.Execute " Update A05_piao Set flag=1" '参与过的标记 Call A_abc '记票后清除各个数组及变量供采集数据用 lstFields.Clear '记票后清空ListBox控件。 Call p_abc '记票后重新装入20位候选人物信息 Text1.Text = "" '记票后清空“身份证”输入框中信息 lstFields.SetFocus '记票后焦点移到ListBox中 End Sub |
Option Explicit Dim mConn As ADODB.Connection Dim RS As New ADODB.Recordset DIM StrCnn As String '连接字符串 Dim A_name() As String '定义姓名数组 Dim A_No() As Integer '定义编号数组 Dim A_TF() As String '逻辑值判断(鼠标的点击过程) Dim I, J, P,P1 As Integer |
Private Sub Form_Load() Set mConn = New Connection StrCnn="Provider=SQLoledb;DataSource=USER2;Userid=sa;pwd=;Initial atalog=My_data" mConn.CursorLocation = adUseClient '设置为客户端 mConn.Open StrCnn Call p_abc '此过程为装入“候选20位”数据 Call A_abc '此过程清空各个数组及变量采集数据用 End Sub |
frm_GRP.show vbmodal |
frm_Pic.show vbmodal |
图片2 |