📄 frm_userlabel.frm
字号:
Dim start As String
Dim end_s As String
On Error GoTo hander
If Option3.Value = True Then
start = ""
end_s = ""
If Len(Trim(txt_from.Text)) = 0 Then
start = "0000"
Else
start = Format(txt_from.Text, "0###")
End If
If Option1.Value = True Then
adotemp.RecordSource = "select user.usercode as [用户编码],user.name as [用户名],town.name as [乡镇],village.name as [村] from user inner join ( village inner join town on village.townid=town.id ) on user.villid=village.id where village.name='" & Trim(txt_vill.Text) & "'"
adotemp.Refresh
End If
If Option4.Value = True Then
adotemp.RecordSource = "select user.usercode as [用户编码],user.name as [用户名],town.name as [乡镇],village.name as [村] from user inner join ( village inner join town on village.townid=town.id ) on user.villid=village.id where village.name='" & Trim(Combo_vill.Text) & "' and town.name='" & Trim(Combo_town.Text) & "'"
adotemp.Refresh
End If
If Len(Trim(txt_to.Text)) = 0 Then
end_s = Format(adotemp.Recordset.RecordCount, "0###")
Else
end_s = Format(txt_to.Text, "0###")
End If
End If
If Option4.Value = True Then
If Option2.Value = True Then
adotemp.RecordSource = "select user.usercode as [用户编码],user.name as [用户名],town.name as [乡镇],village.name as [村] from user inner join ( village inner join town on village.townid=town.id ) on user.villid=village.id where village.name='" & Trim(Combo_vill.Text) & "' and town.name='" & Trim(Combo_town.Text) & "'"
adotemp.Refresh
End If
If Option3.Value = True Then
adotemp.RecordSource = "select user.usercode as [用户编码],user.name as [用户名],town.name as [乡镇],village.name as [村] from user inner join ( village inner join town on village.townid=town.id ) on user.villid=village.id where village.name='" & Trim(Combo_vill.Text) & "' and town.name='" & Trim(Combo_town.Text) & "'and user.usercode >= '" & start & "' and user.usercode <='" & end_s & "'"
adotemp.Refresh
End If
If adotemp.Recordset.RecordCount = 0 Then
MsgBox "没有检索到数据!", vbCritical
End If
End If
If Option1.Value = True Then
If Option2.Value = True Then
adotemp.RecordSource = "select user.usercode as [用户编码],user.name as [用户名],town.name as [乡镇],village.name as [村] from user inner join ( village inner join town on village.townid=town.id ) on user.villid=village.id where village.name='" & Trim(txt_vill.Text) & "'"
adotemp.Refresh
End If
If Option3.Value = True Then
adotemp.RecordSource = "select user.usercode as [用户编码],user.name as [用户名],town.name as [乡镇],village.name as [村] from user inner join ( village inner join town on village.townid=town.id ) on user.villid=village.id where village.name='" & Trim(txt_vill.Text) & "'and user.usercode >= '" & start & "' and user.usercode <='" & end_s & "'"
adotemp.Refresh
End If
If adotemp.Recordset.RecordCount = 0 Then
MsgBox "没有检索到数据!", vbCritical
txt_vill.SelStart = 0
txt_vill.SelLength = Len(txt_vill.Text)
End If
End If
With adotemp.Recordset
ListView.ListItems.Clear
If .RecordCount <> 0 Then
cmd_print.Enabled = True
Screen.MousePointer = 11
xiang = .Fields("乡镇")
zhen = .Fields("村")
For i = 0 To .RecordCount
Set xitem = ListView.ListItems.Add(, , .Fields("用户编码"))
xitem.SubItems(1) = .Fields("用户名")
If .AbsolutePosition = .RecordCount Then
.MoveLast
Exit For
Else
.MoveNext
End If
xitem.SubItems(2) = .Fields("用户编码")
xitem.SubItems(3) = .Fields("用户名")
If .AbsolutePosition = .RecordCount Then
.MoveLast
Exit For
Else
.MoveNext
End If
Next
Screen.MousePointer = 0
End If
End With
hander:
Select Case Err.Number
Case 482:
MsgBox "打印机错误!", vbCritical
Exit Sub
Case Else
Resume Next
End Select
End Sub
Private Sub cmd_print_Click()
Dim i As Integer
Dim j As Integer
Dim start As String
Dim end_s As String
Dim k As Integer
Dim temp_string As String
On Error GoTo hander
Call printer_init '设置坐标的全部长度
Printer.CurrentY = 7
Printer.CurrentX = 7
' Printer.Orientation = 1 '横向打印
' Printer.PaperSize '自定义打印大小
' Printer.PrintQuality = -4 '按高
Printer.Print Space(7) & xiang & zhen & "用户标签"
Printer.Print
Printer.FontSize = 14
Printer.Print Space(10) & "制表日期:" & Date & Space(30) & "第" & Printer.Page; "页"
Printer.Print
Printer.FontSize = 16
'Printer.Print Space(6) & "用户编码" & Space(8) & "用户名" & Space(10) & "用户编码" & Space(8) & "用户名"
Printer.FontSize = 25
j = 0
For i = 1 To ListView.ListItems.Count
If j < 18 Then
Printer.Print Space(3) & Right(ListView.ListItems(i).Text, 4) & Space(4) & ListView.ListItems(i).SubItems(1) & Space(8) & Right(ListView.ListItems(i).SubItems(2), 4) & Space(4) & ListView.ListItems(i).SubItems(3)
j = j + 1
Else
Printer.Print Space(3) & Right(ListView.ListItems(i).Text, 4) & Space(4) & ListView.ListItems(i).SubItems(1) & Space(8) & Right(ListView.ListItems(i).SubItems(2), 4) & Space(4) & ListView.ListItems(i).SubItems(3)
Printer.Print
Printer.NewPage
Printer.FontSize = 20
Printer.Print Space(7) & xiang & zhen & "用户标签"
Printer.Print
j = 0
Printer.FontSize = 14
Printer.Print Space(10) & "制表日期:" & Date & Space(30) & "第" & Printer.Page; "页"
Printer.Print
Printer.FontSize = 16
'Printer.Print Space(6) & "用户编码" & Space(8) & "用户名" & Space(10) & "用户编码" & Space(8) & "用户名"
Printer.FontSize = 25
End If
Next
Printer.EndDoc
hander:
Select Case Err.Number
Case 482:
MsgBox "打印机错误!", vbCritical
Exit Sub
Case Else
Resume Next
End Select
End Sub
Private Sub combo_town_Click()
Dim i As Integer
adotemp.RecordSource = "select village.name as [村] from village inner join town on village.townid=town.id where town.name='" & Trim(Combo_town.Text) & "'"
adotemp.Refresh
Combo_vill.Clear
With adotemp.Recordset
If .RecordCount <> 0 Then
For i = 0 To .RecordCount - 1
Combo_vill.AddItem .Fields("村")
If .AbsolutePosition = .RecordCount Then
.MoveLast
Else
.MoveNext
End If
Next
Combo_vill.ListIndex = 0
End If
End With
End Sub
Private Sub Combo_vill_Click()
cmd_find.Enabled = True
'Option2.Enabled = True
End Sub
Private Sub Form_Load()
Dim i As Integer
On Error Resume Next
Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2 - 700
adotemp.ConnectionString = "DBQ=" & data_basename & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=281;FIL=MS Access;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;PWD=d^j&d*s!j~;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"
adotemp.RecordSource = "select name as [乡镇] from town"
adotemp.Refresh
ListView.ColumnHeaders.Add , , "用户标签", ListView.Width / 4
ListView.ColumnHeaders.Add , , "用户名", ListView.Width / 4
ListView.ColumnHeaders.Add , , "用户标签", ListView.Width / 4
ListView.ColumnHeaders.Add , , "用户名", ListView.Width / 4
ListView.View = lvwReport
With adotemp.Recordset
If .RecordCount <> 0 Then
For i = 0 To .RecordCount - 1
Combo_town.AddItem .Fields("乡镇")
If .AbsolutePosition = .RecordCount Then
.MoveLast
Else
.MoveNext
End If
Next
Combo_town.ListIndex = 0
End If
End With
txt_vill.Enabled = False
cmd_print.Enabled = False
txt_from.Enabled = False
txt_to.Enabled = False
'Option2.Enabled = False
'Option3.Enabled = False
cmd_print.Enabled = False
End Sub
Private Sub ListView_BeforeLabelEdit(Cancel As Integer)
Cancel = True
End Sub
Private Sub Option1_Click()
cmd_print.Enabled = False
Combo_town.Enabled = False
Combo_vill.Enabled = False
txt_vill.Enabled = True
End Sub
Private Sub Option2_Click()
txt_from.Enabled = False
txt_to.Enabled = False
End Sub
Private Sub Option3_Click()
txt_from.Enabled = True
txt_to.Enabled = True
End Sub
Private Sub Option4_Click()
txt_vill.Enabled = False
Combo_vill.Enabled = True
Combo_town.Enabled = True
End Sub
Private Sub txt_to_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If Len(Trim(txt_to.Text)) <> 0 Then
If CLng((txt_from.Text)) - CLng(Trim(txt_to.Text)) > 0 Then
MsgBox "范围输入错误!起始范围大于结束范围!请重输.", vbCritical
Exit Sub
End If
End If
End If
End Sub
Private Sub txt_vill_Change()
If Len(Trim(txt_vill.Text)) <> 0 Then
cmd_find.Enabled = True
cmd_print.Enabled = False
txt_from.Enabled = False
txt_to.Enabled = False
Option2.Enabled = True
Option3.Enabled = True
Else
cmd_print.Enabled = False
txt_from.Enabled = False
txt_to.Enabled = False
Option2.Enabled = False
Option3.Enabled = False
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -