📄 thismonthspecialform.frm
字号:
VERSION 5.00
Begin VB.Form ThisMonthSpecialForm
AutoRedraw = -1 'True
Caption = "当月特殊项表"
ClientHeight = 8055
ClientLeft = 60
ClientTop = 345
ClientWidth = 12840
LinkTopic = "Form1"
MDIChild = -1 'True
ScaleHeight = 8055
ScaleWidth = 12840
Begin VB.CommandButton cmdCancel
Caption = "取消"
Height = 495
Left = 10920
TabIndex = 3
Top = 1680
Width = 1455
End
Begin VB.CommandButton cmdGenerate
Caption = "生成报表"
Height = 495
Left = 10920
TabIndex = 2
Top = 240
Width = 1455
End
Begin VB.CommandButton cmdPrint
Caption = "打印报表"
Height = 495
Left = 10920
TabIndex = 1
Top = 960
Width = 1455
End
Begin VB.OLE OLE1
Height = 7695
Left = 240
SizeMode = 3 'Zoom
TabIndex = 0
Top = 120
Width = 10455
End
End
Attribute VB_Name = "ThisMonthSpecialForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'月份
Dim mMonth As String
'SQL语句, Excel表对象
Dim SQL As String, mSheet As Worksheet
Private Sub cmdCancel_Click()
Me.Hide
End Sub
'生成报表
Private Sub cmdGenerate_Click()
'打开错误处理陷阱
Dim intErrFileNo As Integer '自由文件号
On Error GoTo ErrGoto
'----------------------------------------------------
'Excel对象
Set gX = GetObject("", "Excel.Application")
SQL = "SELECT * FROM 特殊项 WHERE 特殊项日期 >= #" & Format(Date - 30, "YYYY-MM") & _
"# AND 特殊项日期 < #" & Format(Date, "YYYY-MM") & "#"
OpenRS (SQL)
'如果有特殊项
If Not (gRst.BOF Or gRst.EOF) Then
gRst.MoveFirst
Dim i As Integer
i = 0
gX.Workbooks.Close
gX.Workbooks.Add
gX.Visible = True
Set mSheet = gX.ActiveSheet
i = i + 1
mSheet.Cells(i, 1) = mMonth
i = i + 1
'表头
mSheet.Cells(i, 1) = "特殊项ID"
mSheet.Cells(i, 2) = "职工ID"
mSheet.Cells(i, 3) = "特殊项名称"
mSheet.Cells(i, 4) = "特殊项金额"
mSheet.Cells(i, 5) = "特殊项日期"
While Not gRst.EOF
i = i + 1
'各项值
mSheet.Cells(i, 1) = gRst("特殊项ID")
mSheet.Cells(i, 2) = gRst("职工ID")
mSheet.Cells(i, 3) = gRst("特殊项名称")
mSheet.Cells(i, 4) = gRst("特殊项金额")
mSheet.Cells(i, 5) = CDate(gRst("特殊项日期"))
gRst.MoveNext
Wend
CloseRS
'设置格式
mSheet.Columns("A:F").ColumnWidth = 12
gX.ActiveWorkbook.SaveAs App.Path & "\" & mMonth & "特殊项表.xls"
OLE1.CreateLink App.Path & "\" & mMonth & "特殊项表.xls"
Else
MsgBox "本月没有任何特殊项"
End If
'----------------------------------------------------
Exit Sub
'-----------------------------
ErrGoto:
'把错误信息保存在文件里
intErrFileNo = FreeFile()
Open "YFSystem.ini" For Append As intErrFileNo
Print #intErrFileNo, Chr(34) + Format(Now, "YYYY-MM-DD HH:MM:SS") + Chr(34), Chr(34) + "信息" + Chr(34), Chr(34) + Err.Description + Chr(34), Chr(34) + "cmdGenerate_Click(ThisMonthSalaryForm)" + Chr(34), Chr(34) + App.Title + Chr(34)
Close #intErrFileNo
End Sub
Private Sub cmdPrint_Click()
mSheet.PrintOut
End Sub
Private Sub Form_Load()
mMonth = Format(Date - 30, "YYYYMM")
End Sub
Private Sub OLE1_Updated(Code As Integer)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -