Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Access report via vb


Reply
 
Thread Tools Display Modes
  #1  
Old 07-18-2003, 04:52 AM
PeterUKVB PeterUKVB is offline
Newcomer
 
Join Date: Jul 2003
Posts: 11
Default Access report via vb


In my vb project it uses an access database that i want to print out as a access report using a certain query string (the data source will change)

ive managed to print out the report from VB (the first section of coding)
and ive managed to populate the report from within access (in the 2nd section of coding) but how can i have all the coding in just vb please so i can send the current recordsource created in vb to the report so i can the report data i need

Printing the report from VB
Code:
On Error GoTo HandleErrors

'points to the location of the database to open
Dim dbName As String
'name of the report to print
Dim rptName As String
'print type
Dim Preview As Long
'used to story current main recordset
Dim strFilter As String

'doesnt seem needed
'Const acNormal = 0
'Const acPreview = 2

Dim appAccess  As Access.Application
Set appAccess = New Access.Application


dbName = App.Path & "\nhsdirectory.mdb"
rptName = "AllStaffRecs"
Preview = acPreview 'acNormal


With appAccess
    '.OpenCurrentDatabase (App.Path & "\nhsdirectory.mdb")
    .OpenCurrentDatabase filepath:=dbName
    'if user wants to preview print first then show print preview screen
    If Preview = acPreview Then
        'alow the user to see the report
       .Visible = True
       'open report in preview mode
       .DoCmd.OpenReport rptName, acViewPreview
    Else
        'open the report
       .DoCmd.OpenReport rptName
       
    End If
End With

ExitHere:
    Exit Sub

HandleErrors:
    Select Case Err.Number
        Case 2501
            MsgBox "No rows have been selected to print", vbOKOnly, "Print Error"
        Case Else
            MsgBox Err.Description, vbOKOnly, "Print Error"
    End Select
    Resume ExitHere
    
End Sub
Selecting the data to print in the report in accesses (currently prints all the records)


Code:
Option Compare Database
Option Explicit

' From Access 2002 Desktop Developer's Handbook
' by Litwin, Getz, and Gunderloy (Sybex)
' Copyright 2001.  All rights reserved.

Private Sub Report_Open(Cancel As Integer)
    ' You didn't know how many columns, or what
    ' their names would be, until now.
    ' Fill in the label captions,
    ' and control ControlSources.
    
    Dim intColCount As Integer
    Dim intControlCount As Integer
    Dim i As Integer
    Dim strName As String
    
    On Error Resume Next
    
    Dim rst As ADODB.Recordset
    
    Set rst = New ADODB.Recordset
    
    rst.Open _
    Source:=Me.RecordSource, _
    ActiveConnection:=CurrentProject.Connection, _
    Options:=adCmdTable
    
    intColCount = rst.Fields.Count
    intControlCount = Me.Detail.Controls.Count
    
    If intControlCount < intColCount Then
        intColCount = intControlCount
    End If
    
    ' Fill in information for the necessary controls.
    For i = 1 To intColCount
        strName = rst.Fields(i - 1).Name
        Me.Controls("lblHeader" & i).Caption = strName
        Me.Controls("txtData" & i).ControlSource = strName
        'Me.Controls("txtSum" & i).ControlSource = _
        ' "=Sum([" & strName & "])"
    Next i
    
    ' Hide the extra controls.
    For i = intColCount + 1 To intControlCount
        Me.Controls("txtData" & i).Visible = False
        Me.Controls("lblHeader" & i).Visible = False
        'Me.Controls("txtSum" & i).Visible = False
    Next i
    
    ' Close the recordset.
    rst.Close
End Sub
Reply With Quote
  #2  
Old 07-18-2003, 08:26 AM
PeterUKVB PeterUKVB is offline
Newcomer
 
Join Date: Jul 2003
Posts: 11
Default

i know theres a lot of code to go through so i thought id try and explain it a lot easier i guess my main problem is i cant use

Me.Detail.Controls.Count in vb as im not execusing the code from access so what would i neeed to replace me with in order to refere to that database im guessing its something like
appaccess.reports("allstaffrecs").Controls.Count fore example if that makes my question a lot easier

Peter
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
producing access report with vb recordset khanman Database and Reporting 4 03-02-2003 11:00 PM
vb and MS access Report kristine Database and Reporting 1 01-25-2003 11:00 AM
Printing Access Report from VB JerryEng Database and Reporting 3 11-27-2002 01:57 PM
Access Report Design nickg96 Database and Reporting 4 08-19-2002 01:12 PM
QB to VB Conversion - By AIO BillSoo Tutors' Corner 0 08-06-2002 11:37 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->