?? 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 + -