VB中怎么载如或显示Access数据库中的报表

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

VB中怎么载如或显示Access数据库中的报表

'首先在“工程/引用”菜单下引用Microsoft Access 9.0 Object Library

Option Explicit

Dim MSAccess As Access.Application

Private Sub Command1_Click()

Set MSAccess = New Access.Application

MSAccess.OpenCurrentDatabase (App.Path & "\db1.mdb")

MSAccess.DoCmd.OpenReport "rptTB", acViewNormal

MSAccess.CloseCurrentDatabase

Set MSAccess = Nothing

End Sub

rptTB是access中的一个报表名称

要引用Microsoft Access 9.0 Object Library

dim objAccess As Access.Application

Set objAccess = CreateObject("Access.Application")

objAccess.OpenCurrentDatabase ("c:\1.mdb")

objAccess.DoCmd.OpenReport "ReportName", acViewPreview

objAccess.Visible = True

这个要引用Microsoft Access 9.0 Object Library(Office 2000)

我没试过Office97会怎么样。

∙VB中打印ACCESS报表

∙作者:aspxer 来源:internet 日期:2007-5-20 13:56:44 关键字:

VB中打印ACCESS报表

acc As Object

Set acc = CreateObject("Access.Application")

If Right$(Trim$(App.Path), 1) = "\" Then

acc.OpenCurrentDatabase App.Path & "data.mdb"

@#打开数据库

Else

acc.OpenCurrentDatabase App.Path & "\data.mdb"

End If

acc.docmd.OpenReport "打印准考证" @#, acPreview

打印报表“打印准考证”

acc.Quit

Set acc = Nothing

使用ACCESS报表主要缺点就是不能预览

Dim acc As Object

Set acc = CreateObject("Access.Application")

If Right$(Trim$(App.Path), 1) = "\" Then

acc.OpenCurrentDatabase App.Path & "data.mdb"

'打开数据库

Else

acc.OpenCurrentDatabase App.Path & "\data.mdb"

End If

acc.docmd.OpenReport "打印准考证" ', acPreview

打印报表“打印准考证”

acc.Quit

Set acc = Nothing使用ACCESS报表主要缺点就是不能预览

怪问题:在Access 里新建了报表后,VB/VC 可不可以直接调用并打印?'先引用access obj

Option Explicit

Private Sub Form_Load()

Call PrintReport(App.Path & "\test.mdb", "test")

End Sub

Private Function PrintReport(ByVal MdbFileName As String, ByVal ReportName As Stri ng) As Boolean

On Error GoTo ErrTrap

Dim localReport As New Access.Application

Call localReport.OpenCurrentDatabase(MdbFileName)

Call localReport.DoCmd.OpenReport(ReportName, acViewDesign)

Call localReport.DoCmd.Close

Call localReport.DoCmd.Maximize

localReport.Visible = True

Call localReport.DoCmd.OpenReport(ReportName, acViewNormal)

Call localReport.Quit

Set localReport = Nothing

PrintReport = True

GoTo Fun_exit

ErrTrap:

PrintReport = False

Call localReport.Quit

Set localReport = Nothing

Fun_exit:

End Function

可不可以在VB里调用ACCESS表象调用EXCEL一样容易

Dim conn As New ADODB.Connection

Dim cona As New ADODB.Connection

Dim rs As New ADODB.Recordset

Dim ra As New ADODB.Recordset

'连接access

conn.ConnectionString = "driver={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\xxx.mdb;password=xxx"

conn.Open

'连接excel

cona.ConnectionString = "driver={Microsoft Access Driver (*.xls)};DBQ=" & App.Path & "\xxx.xls;password=xxx"

cona.Open

'打开并查询access表

rs.cursorlocation=3

rs.Open "select * from xxx where ....", conn

相关文档
最新文档