VB中怎么载如或显示Access数据库中的报表'首先在“工程/引用”菜单下引用Microsoft Access 9.0 Object LibraryOption ExplicitDim MSAccess As Access.ApplicationPrivate Sub Command1_Click()Set MSAccess = New Access.ApplicationMSAccess.OpenCurrentDatabase (App.Path & "\db1.mdb")MSAccess.DoCmd.OpenReport "rptTB", acViewNormalMSAccess.CloseCurrentDatabaseSet MSAccess = NothingEnd SubrptTB是access中的一个报表名称要引用Microsoft Access 9.0 Object Librarydim objAccess As Access.ApplicationSet objAccess = CreateObject("Access.Application")objAccess.OpenCurrentDatabase ("c:\1.mdb")objAccess.DoCmd.OpenReport "ReportName", acViewPreviewobjAccess.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 ObjectSet acc = CreateObject("Access.Application")If Right$(Trim$(App.Path), 1) = "\" Thenacc.OpenCurrentDatabase App.Path & "data.mdb"@#打开数据库Elseacc.OpenCurrentDatabase App.Path & "\data.mdb"End Ifacc.docmd.OpenReport "打印准考证" @#, acPreview打印报表“打印准考证”acc.QuitSet acc = Nothing使用ACCESS报表主要缺点就是不能预览Dim acc As ObjectSet acc = CreateObject("Access.Application")If Right$(Trim$(App.Path), 1) = "\" Thenacc.OpenCurrentDatabase App.Path & "data.mdb"'打开数据库Elseacc.OpenCurrentDatabase App.Path & "\data.mdb"End Ifacc.docmd.OpenReport "打印准考证" ', acPreview打印报表“打印准考证”acc.QuitSet acc = Nothing使用ACCESS报表主要缺点就是不能预览怪问题:在Access 里新建了报表后,VB/VC 可不可以直接调用并打印?'先引用access objOption ExplicitPrivate Sub Form_Load()Call PrintReport(App.Path & "\test.mdb", "test")End SubPrivate Function PrintReport(ByVal MdbFileName As String, ByVal ReportName As Stri ng) As BooleanOn Error GoTo ErrTrapDim localReport As New Access.ApplicationCall localReport.OpenCurrentDatabase(MdbFileName)Call localReport.DoCmd.OpenReport(ReportName, acViewDesign)Call localReport.DoCmd.CloseCall localReport.DoCmd.MaximizelocalReport.Visible = TrueCall localReport.DoCmd.OpenReport(ReportName, acViewNormal)Call localReport.QuitSet localReport = NothingPrintReport = TrueGoTo Fun_exitErrTrap:PrintReport = FalseCall localReport.QuitSet localReport = NothingFun_exit:End Function可不可以在VB里调用ACCESS表象调用EXCEL一样容易Dim conn As New ADODB.ConnectionDim cona As New ADODB.ConnectionDim rs As New ADODB.RecordsetDim ra As New ADODB.Recordset'连接accessconn.ConnectionString = "driver={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\xxx.mdb;password=xxx"conn.Open'连接excelcona.ConnectionString = "driver={Microsoft Access Driver (*.xls)};DBQ=" & App.Path & "\xxx.xls;password=xxx"cona.Open'打开并查询access表rs.cursorlocation=3rs.Open "select * from xxx where ....", conn'打开excel表ra.cursorlocation=3ra.Open "select * from [xxx]", cona'新增到Excelra.addnewra("xx")=rs("xxx")....ra.updaters.closera.closeset conn=nothingset cona=nothing能在VB中调用ACCESS中的窗体吗?OpenCurrentDatabase 方法示例以下示例通过“自动化”(Automation) 从其他应用程序中打开一个Microsoft Access 数据库,然后打开一个数据库中的窗体。
可以在任何一个能作为COM 组件的应用程序的Visual Basic 模块中键入这段代码。
例如,可以从Microsoft Excel、Microsoft Visual 或Microsoft Access 中运行下列代码。
当指向Application 对象的变量超出范围时,它所表示的Microsoft Access 实例也将关闭。
所以,必须在模块级说明这个变量。
' 在模块的声明节中包含以下语句。
Dim appAccess As Access.ApplicationSub DisplayForm()' 将字符串初始化为数据库的路径。
Const strConPathToSamples = "C:\Program " _& "Files\Microsoft Office\Office\Samples\Northwind.mdb"strDB = strConPathToSamples & "Northwind.mdb"' 创建Microsoft Access 的实例。
Set appAccess = _CreateObject("Access.Application")' 在Microsoft Access 窗口中打开数据库。
appAccess.OpenCurrentDatabase strConPathToSamples' 打开“Orders”窗体。
appAccess.DoCmd.OpenForm "Orders"End Sub请教各位,如何在vb的窗体中,调用或显示access中做的报表。
Dim objAccess As Access.ApplicationSet objAccess = CreateObject("Access.Application")objAccess.OpenCurrentDatabase ("c:\1.mdb")objAccess.DoCmd.OpenReport "report1", acViewPreviewobjAccess.Visible = True。