VB这个程序谁能告诉我是从哪里连接数据库的 谢谢了
PrivateSub日报_Click()OnErrorResumeNextSelectDate=Format(DTPicker1.Value,"yyyy-mm-dd")I...
Private Sub 日报_Click()
On Error Resume Next
SelectDate = Format(DTPicker1.Value, "yyyy-mm-dd")
If Dir("c:\报表", vbDirectory) = "" Then
MkDir "c:\报表"
MkDir "c:\报表\日报"
MkDir "c:\报表\月报"
MkDir "c:\报表\年报"
End If
openFile = "c:\报表\日报\"
End Sub
Private Sub 日报查看_Click()
On Error Resume Next
消息.Caption = "正在显示日报请稍候..."
Call 日报_Click
Dim StrDir As String
StrDir = "c:\报表\日报\"
Set xlApp = New Excel.Application
xlApp.DisplayAlerts = False
xlApp.Visible = False
On Error GoTo ErrorHandle
Set xlBook = xlApp.Workbooks.Open(StrDir & SelectDate & ".xls", , False)
Set xlSheet = xlBook.Worksheets(1)
xlApp.Visible = True
xlApp.DisplayAlerts = False
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
消息.Caption = "日报显示完毕,可以查看!"
Exit Sub
ErrorHandle:
xlApp.Visible = False
xlApp.DisplayAlerts = False
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
消息.Caption = "所选日期报表不存在!请先生成报表!"
MsgBox "所选日期报表不存在!请先生成报表!"
End Sub
'——————————————————————日报生成并显示——————————————————————
Private Sub 日报生成_Click()
On Error Resume Next
消息.Caption = "正在生成日报,时间较长请稍候..."
Call 日报_Click
Dim StrDir As String
StrDir = App.Path & "\报表\模板\"
Dim saveFile As String
saveFile = "c:\报表\日报\"
Dim i As Long
Dim sPro As String
Dim sSer As String
Dim sCon As String
Dim ssql As String
Dim m, n, s
sPro = "Provider=WinCCOLEDBProvider.1;"
sSer = "Data Source=.\WinCC"
sCon = sPro + sDsn + sSer
startTime = SelectDate & " 08:00:00"
beginTime = DateAdd("h", -7, startTime)
endTime = DateAdd("s", -1, DateAdd("h", 24, beginTime))
Set cnADO = CreateObject("ADODB.Connection")
cnADO.ConnectionString = sCon
cnADO.CursorLocation = 3
cnADO.Open
Set rsADO = CreateObject("ADODB.Recordset")
Set cmADO = CreateObject("ADODB.Command")
cmADO.CommandType = 1
Set cmADO.ActiveConnection = cnADO
Set xlApp = New Excel.Application
xlApp.DisplayAlerts = False
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open(StrDir & "Day.xls")
'—*—*—*—*—*—*—*—*—*—*—*—*—开始产生Sheet—*—*—*—*—*—*—*—*—*—*—*—*—
Call CuGeShan
'—*—*—*—*—*—*—*—*—*—*—*—*—结束产生Sheet—*—*—*—*—*—*—*—*—*—*—*—*—
xlApp.Visible = True
xlApp.DisplayAlerts = False
xlBook.SaveAs FileName:=saveFile & SelectDate & ".xls"
'xlBook.Close (True)
'xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
cnADO.Close
Set cnADO = Nothing
Set rsADO = Nothing
消息.Caption = "日报生成并显示完毕,请查看!"
End Sub
Dim m, n, s
sPro = "Provider=WinCCOLEDBProvider.1;"
sSer = "Data Source=.\WinCC"
sCon = sPro + sDsn + sSer
startTime = SelectDate & " 08:00:00"
beginTime = DateAdd("h", -7, startTime)
endTime = DateAdd("s", -1, DateAdd("h", 24, beginTime))
这个时间是什么意思 展开
On Error Resume Next
SelectDate = Format(DTPicker1.Value, "yyyy-mm-dd")
If Dir("c:\报表", vbDirectory) = "" Then
MkDir "c:\报表"
MkDir "c:\报表\日报"
MkDir "c:\报表\月报"
MkDir "c:\报表\年报"
End If
openFile = "c:\报表\日报\"
End Sub
Private Sub 日报查看_Click()
On Error Resume Next
消息.Caption = "正在显示日报请稍候..."
Call 日报_Click
Dim StrDir As String
StrDir = "c:\报表\日报\"
Set xlApp = New Excel.Application
xlApp.DisplayAlerts = False
xlApp.Visible = False
On Error GoTo ErrorHandle
Set xlBook = xlApp.Workbooks.Open(StrDir & SelectDate & ".xls", , False)
Set xlSheet = xlBook.Worksheets(1)
xlApp.Visible = True
xlApp.DisplayAlerts = False
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
消息.Caption = "日报显示完毕,可以查看!"
Exit Sub
ErrorHandle:
xlApp.Visible = False
xlApp.DisplayAlerts = False
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
消息.Caption = "所选日期报表不存在!请先生成报表!"
MsgBox "所选日期报表不存在!请先生成报表!"
End Sub
'——————————————————————日报生成并显示——————————————————————
Private Sub 日报生成_Click()
On Error Resume Next
消息.Caption = "正在生成日报,时间较长请稍候..."
Call 日报_Click
Dim StrDir As String
StrDir = App.Path & "\报表\模板\"
Dim saveFile As String
saveFile = "c:\报表\日报\"
Dim i As Long
Dim sPro As String
Dim sSer As String
Dim sCon As String
Dim ssql As String
Dim m, n, s
sPro = "Provider=WinCCOLEDBProvider.1;"
sSer = "Data Source=.\WinCC"
sCon = sPro + sDsn + sSer
startTime = SelectDate & " 08:00:00"
beginTime = DateAdd("h", -7, startTime)
endTime = DateAdd("s", -1, DateAdd("h", 24, beginTime))
Set cnADO = CreateObject("ADODB.Connection")
cnADO.ConnectionString = sCon
cnADO.CursorLocation = 3
cnADO.Open
Set rsADO = CreateObject("ADODB.Recordset")
Set cmADO = CreateObject("ADODB.Command")
cmADO.CommandType = 1
Set cmADO.ActiveConnection = cnADO
Set xlApp = New Excel.Application
xlApp.DisplayAlerts = False
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open(StrDir & "Day.xls")
'—*—*—*—*—*—*—*—*—*—*—*—*—开始产生Sheet—*—*—*—*—*—*—*—*—*—*—*—*—
Call CuGeShan
'—*—*—*—*—*—*—*—*—*—*—*—*—结束产生Sheet—*—*—*—*—*—*—*—*—*—*—*—*—
xlApp.Visible = True
xlApp.DisplayAlerts = False
xlBook.SaveAs FileName:=saveFile & SelectDate & ".xls"
'xlBook.Close (True)
'xlApp.Quit
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
cnADO.Close
Set cnADO = Nothing
Set rsADO = Nothing
消息.Caption = "日报生成并显示完毕,请查看!"
End Sub
Dim m, n, s
sPro = "Provider=WinCCOLEDBProvider.1;"
sSer = "Data Source=.\WinCC"
sCon = sPro + sDsn + sSer
startTime = SelectDate & " 08:00:00"
beginTime = DateAdd("h", -7, startTime)
endTime = DateAdd("s", -1, DateAdd("h", 24, beginTime))
这个时间是什么意思 展开
1个回答
展开全部
Set cnADO = CreateObject("ADODB.Connection")
cnADO.ConnectionString = sCon
cnADO.CursorLocation = 3
cnADO.Open
Set rsADO = CreateObject("ADODB.Recordset")
Set cmADO = CreateObject("ADODB.Command")
cmADO.CommandType = 1
Set cmADO.ActiveConnection = cnADO
==========================
beginTime = DateAdd("h", -7, startTime)
'把startTime小时数(h)减7
'其它同理,参考DateAdd()函数
cnADO.ConnectionString = sCon
cnADO.CursorLocation = 3
cnADO.Open
Set rsADO = CreateObject("ADODB.Recordset")
Set cmADO = CreateObject("ADODB.Command")
cmADO.CommandType = 1
Set cmADO.ActiveConnection = cnADO
==========================
beginTime = DateAdd("h", -7, startTime)
'把startTime小时数(h)减7
'其它同理,参考DateAdd()函数
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询