Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012
    Posts
    1

    Unanswered: Creating a form letter

    (Access 2007)

    I've been working on this a while and I found that in order for a button on a form to open a report and for all the fields on the form to appear in the report, the record source of both the form and the report have to be the same. Doing this from my test db, I based my form and report on a query of several tables and was able to click the button to open the report. Everything worked great.

    On my live db, however, there are 900+ records. The form I'm using to view the records (frmPrchsReview) is based on the db's main table (tblPurchases). The tab page with the command button is part of the frmPrchsReview form. On this tab page, there are also radio buttons which let the reviewer choose which category the purchase falls into. When the command button is clicked, a new form pops with a basic outline of the letter. The new form (frmRvwLetter) needs to include the PurchaseID from the frmPrchsReview form's current record, the PurchaseName from frmPrchsReview form's current record and a paragraph from a different table, tblLetterContent, that corresponds to the radio button category chosen. The new form, frmRvwLetter, needs to open because it contains a textbox where the manager enters a sentence or two which must appear on the letter, rptLetter. Once the text is entered, another command button on frmRvwLetter is clicked to open rptLetter.

    In my vast experience with Access (since March) which made me believe I had to base a form and the report which comes from the form on the same record source, it seems I need to do this with the command buttons:

    Command button 1 on frmPrchsReview (Tab 3):
    From frmPuchsReview, get the PurchaseID and PurchaseName from the current record; then, get the paragraph from tblLetterContent that matches the radio button chosen on the tab page, and put them on frmRvwLetter.

    Command button 2 on frmRvwLetter:
    Then, get the PurchaseID, PurchaseName, paragraph text and the sentence entered by the manager and put it on rptLetter.

    Am I way off? How do I do it?

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    When you issue a DoCmd.OpenReport command to open a Report, there are additional parameters that you can include in the instruction and that are used to filter the data from the Report RecordSource (Table or Query):
    Code:
    DoCmd.OpenReport(ReportName, View, FilterName, WhereCondition, WindowMode, OpenArgs)
    More complex data selection can be performed using the OpenArgs parameter by writing some code to analyze its contents and configure the Report accordingly.
    Have a nice day!

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by rlntel View Post
    (Access 2007)

    ...I found that in order for a button on a form to open a report and for all the fields on the form to appear in the report, the record source of both the form and the report have to be the same.
    More importantly, before you Open the Report, you have to Save the Current Record, so that it actually is part of the Record Source. Place this immediately before opening the Report:

    DoCmd****nCommand acCmdSaveRecord

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •