Results 1 to 5 of 5
  1. #1
    dabman is offline Novice
    Windows Vista Access 2003
    Join Date
    Dec 2009
    Posts
    2

    Printing reports and cycling through records

    Hi folks,

    I don't have a great deal of experience with VBA, but I have a problem with a database which I suspect might be resolved with the use of VBA.

    To produce a bunch of customer specific reports, I have a form which has records pertaining to each of the unique customer IDs in the database. I also have a report which, by being linked to a query, will produce a report for the customer ID shown in the appropriate field in the form.

    What I would like to do is create a peice of code which will print the specific report, move on to the next record, and then print the next report and so on, until the end of the recordset. Unfortunately, my meagre attempts have been thoroughly unsuccessful thus far.



    Can anyone assist (I suspect it would only take two or three lines of code at the most) as I am totally lost here.

    Thanks in advance,

    B

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Now what u have asked for is not very clear, bcoz this problem can be tackled in so many ways. i offer the simple solution.
    build a form and create a a Combox that will show CustomerIDs (Name the Combobox CB1)
    Prepare the Report that you want to display. make sure the field CustomerID is there in the report.
    Now come back to the Form and go to design view and create a command button and in the Click event type the following code (i assume the name of the Report as Rep1 and the Form Frm1)

    Dim stDocName as String
    Dim stLinkCriteria as String

    stDocName="Rep1"
    stLinkCriteria="[CustomerID]=" & Me![CB1]"

    Docmd OpenReport stDocName,,,stLinkCriteria

    thanx inform me how did it go

  3. #3
    dabman is offline Novice
    Windows Vista Access 2003
    Join Date
    Dec 2009
    Posts
    2
    Hi Maximus,

    Thanks for your advice so far - giving it a go now.

    I have created the form, and the appropriate report.

    When I enter the code your provided into the onclick event, the lines 'stLinkCriteria="[PupilID]=" & Me![CB1]"' and 'Docmd OpenReport stDocName,,,stLinkCriteria' are marked as read, and the first one comes up with an error saying:

    "Compile error: Expected: end of statement"

    Should I be adding something to this (I have altered the name of the report to point to the correct report)?

    As a second question, will this process automate the change of selection in the combobox, much as I had tried to do with record changing in my original example?

    Thanks,

    B

  4. #4
    maximus's Avatar
    maximus is offline Expert
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Well you have to Type End Sub at the end of the code.
    For Your reference I am giving u the complete code
    Say your Command Button name is Command11

    Private Sub Command11_Click()
    Dim stDocName as String
    Dim stLinkCriteria as String

    stDocName="Rep1"
    stLinkCriteria="[CustomerID]=" & Me![CB1]"

    Docmd OpenReport stDocName,,,stLinkCriteria
    End Sub

    Copy and paste this code it will work. Generally the First Line and the Last line are always there by default.

  5. #5
    maximus's Avatar
    maximus is offline Expert
    Windows XP Access 2003
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    As for your second question do you automatically select a value in the combo box if so please let me know i will help. i just want to be sure that i have got u right.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Help with my printing
    By mattwill2001 in forum Queries
    Replies: 4
    Last Post: 08-17-2009, 01:55 AM
  2. printing issues
    By dmmartin in forum Programming
    Replies: 2
    Last Post: 05-29-2009, 08:22 PM
  3. Best way of displaying and printing records?
    By Orabidoo in forum Access
    Replies: 1
    Last Post: 05-11-2009, 10:05 AM
  4. How to automate printing and saving reports
    By lilynet in forum Programming
    Replies: 0
    Last Post: 02-10-2009, 01:33 PM
  5. Printing Reports....
    By Danny Christie in forum Reports
    Replies: 1
    Last Post: 12-06-2006, 05:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums