If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Print Report from a Form
I have a report with a datasource Goals table. I also have a form with a
datasource Goals table. I'd like to create a macro that I can assign to a toolbar button that prints the current record that is open in the form in the report. I'm not sure if it matters, but the Goals table has a multiple primary key of 3 fields; rcdl, desk & goaldate. Thanks for your help. |
#2
|
|||
|
|||
Create a command button on the form where the click event has the OpenReport
method to open the report. Use the values for the current record on the form to build the Where condition for the OpenReport method. See OpenReport in VBA editor help for more details. "Alex" wrote: I have a report with a datasource Goals table. I also have a form with a datasource Goals table. I'd like to create a macro that I can assign to a toolbar button that prints the current record that is open in the form in the report. I'm not sure if it matters, but the Goals table has a multiple primary key of 3 fields; rcdl, desk & goaldate. Thanks for your help. |
#3
|
|||
|
|||
Forms are the interface in Access.
Tables are really just buckets to hold the database. You will find it easier to create a form with a command button than to try to create a generic toolbar button that determines what the key is. On your form, you will have a command button for printing the report. For the code to put in the Click event procedure of this form, see: Print the record in the form at: http://allenbrowne.com/casu-15.html In your case, you have a complex key, so the strWhere will need to read all 3 fields, e.g.: strWhere = "(rcdl = " & Me.rcdl & ") AND (desk = """ & Me.desk & _ """) AND goalDate = " & Format(Me.goaldate, "\#mm\/dd\/yyyy\#") & ")" That example assumes that: - rcdl is a number field (so has no delimters); - desk is a text field (so has " as delimiter); - goaldate is a number field (so as # as delimiter). Modify the delimters to match your actual field types. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Alex" wrote in message ... I have a report with a datasource Goals table. I also have a form with a datasource Goals table. I'd like to create a macro that I can assign to a toolbar button that prints the current record that is open in the form in the report. I'm not sure if it matters, but the Goals table has a multiple primary key of 3 fields; rcdl, desk & goaldate. Thanks for your help. |
#4
|
|||
|
|||
If you add a button to your form, the wizard will walk you right through
printing a report. It will even let you tell it to only print for the current record. -- Rick B "Alex" wrote in message ... I have a report with a datasource Goals table. I also have a form with a datasource Goals table. I'd like to create a macro that I can assign to a toolbar button that prints the current record that is open in the form in the report. I'm not sure if it matters, but the Goals table has a multiple primary key of 3 fields; rcdl, desk & goaldate. Thanks for your help. |
#5
|
|||
|
|||
Thanks - I gave this code a try, but the report opens with the first record,
regardless of which one is currently open in the form. Maybe I have incorrect field names. Example: in "(rcdloc = "" & Me.Rldc & ""), are these table, form or report field names? Thanks Here's my code: Private Sub PrintGoal_Click() Dim strWhere As String If Me.Dirty Then 'Saves any edits Me.Dirty = False End If If Me.NewRecord Then 'Check to see if there is a record to print MsgBox "Select a record to print" Else strWhere = "(rcdloc = "" & Me.Rldc & "") AND (deskcode = "" & Me.desk & "") AND (GoalDate = " & Format(Me.GoalDate, "\#mm\/dd\/yyyy\#") & ")" DoCmd.OpenReport "rptPrintGoal", acViewPreview, strWhere End If End Sub "Allen Browne" wrote: Forms are the interface in Access. Tables are really just buckets to hold the database. You will find it easier to create a form with a command button than to try to create a generic toolbar button that determines what the key is. On your form, you will have a command button for printing the report. For the code to put in the Click event procedure of this form, see: Print the record in the form at: http://allenbrowne.com/casu-15.html In your case, you have a complex key, so the strWhere will need to read all 3 fields, e.g.: strWhere = "(rcdl = " & Me.rcdl & ") AND (desk = """ & Me.desk & _ """) AND goalDate = " & Format(Me.goaldate, "\#mm\/dd\/yyyy\#") & ")" That example assumes that: - rcdl is a number field (so has no delimters); - desk is a text field (so has " as delimiter); - goaldate is a number field (so as # as delimiter). Modify the delimters to match your actual field types. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Alex" wrote in message ... I have a report with a datasource Goals table. I also have a form with a datasource Goals table. I'd like to create a macro that I can assign to a toolbar button that prints the current record that is open in the form in the report. I'm not sure if it matters, but the Goals table has a multiple primary key of 3 fields; rcdl, desk & goaldate. Thanks for your help. |
#6
|
|||
|
|||
The first name in the string is the field name in the table.
The second is the matching text box in your form. It's like: strWhere = "(Field1] = " & Me.Text0 & ... If you created your form using a wizard, the text box will have the same name as the field it is bound to. -- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Alex" wrote in message ... Thanks - I gave this code a try, but the report opens with the first record, regardless of which one is currently open in the form. Maybe I have incorrect field names. Example: in "(rcdloc = "" & Me.Rldc & ""), are these table, form or report field names? Thanks Here's my code: Private Sub PrintGoal_Click() Dim strWhere As String If Me.Dirty Then 'Saves any edits Me.Dirty = False End If If Me.NewRecord Then 'Check to see if there is a record to print MsgBox "Select a record to print" Else strWhere = "(rcdloc = "" & Me.Rldc & "") AND (deskcode = "" & Me.desk & "") AND (GoalDate = " & Format(Me.GoalDate, "\#mm\/dd\/yyyy\#") & ")" DoCmd.OpenReport "rptPrintGoal", acViewPreview, strWhere End If End Sub "Allen Browne" wrote: Forms are the interface in Access. Tables are really just buckets to hold the database. You will find it easier to create a form with a command button than to try to create a generic toolbar button that determines what the key is. On your form, you will have a command button for printing the report. For the code to put in the Click event procedure of this form, see: Print the record in the form at: http://allenbrowne.com/casu-15.html In your case, you have a complex key, so the strWhere will need to read all 3 fields, e.g.: strWhere = "(rcdl = " & Me.rcdl & ") AND (desk = """ & Me.desk & _ """) AND goalDate = " & Format(Me.goaldate, "\#mm\/dd\/yyyy\#") & ")" That example assumes that: - rcdl is a number field (so has no delimters); - desk is a text field (so has " as delimiter); - goaldate is a number field (so as # as delimiter). Modify the delimters to match your actual field types. "Alex" wrote in message ... I have a report with a datasource Goals table. I also have a form with a datasource Goals table. I'd like to create a macro that I can assign to a toolbar button that prints the current record that is open in the form in the report. I'm not sure if it matters, but the Goals table has a multiple primary key of 3 fields; rcdl, desk & goaldate. Thanks for your help. |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Design help, please | SillySally | Using Forms | 27 | March 6th, 2005 04:11 AM |
Print Report Based on Form Data | Matthew Loraditch | Using Forms | 5 | December 31st, 2004 11:34 PM |
Still Hoping for help with a Query problem | Don Sealer | Using Forms | 15 | November 13th, 2004 06:24 AM |
dlookup | miaplacidus | Using Forms | 9 | August 5th, 2004 09:16 PM |
Query Form: Print Report | Dennis | Running & Setting Up Queries | 1 | June 6th, 2004 01:08 PM |