Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159

    Print only Forms specified by user

    Hello,

    I am trying to add a button to a form that will enable a user to type the data they want in a text box and display only those records with the matching data in the specific field. Then by pushing a command button, only these records with the specific data typed in the text box will be printed.

    The article below is exactly what I want, but instead of printing reports I want to print forms.

    http://blogs.techrepublic.com.com/msoffice/?p=747

    Here is the code provided in the article that I need to transform to match my database:
    Dim ReportName
    ReportName = "Employees1"
    DoCmd.OpenReport _
    ReportName:=ReportName, _ view:=acViewPreview, _ WhereCondition:="[Hire Date] Between #" & _ Me.StartDate & "# AND #" & _ Me.EndDate & "#"
    The simple parts that I know (or I think I do) is that I need to change where it says Report to Form (ex. ReportName to FormName, OpenReport to OpenForm). Another difference between this code and the code that I need, is that this code is looking for a range, whereas all I need is just the records that match the one text box. For example, if the user types in Arizona in the text box, only the records with Arizona in the specific field will be shown.

    Any help would be awesome. Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    For starters, I think you'll be a lot happier in the long run creating a report to print. You have a lot more control over how a report prints than a form, and no developer I know of prints forms. Here's the format for a single value (OpenReport works the same in that regard as OpenForm):

    http://www.baldyweb.com/wherecondition.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    Quote Originally Posted by pbaldy View Post
    For starters, I think you'll be a lot happier in the long run creating a report to print. You have a lot more control over how a report prints than a form, and no developer I know of prints forms. Here's the format for a single value (OpenReport works the same in that regard as OpenForm):

    http://www.baldyweb.com/wherecondition.htm

    I probably should throw it over to a report, I can't remember why I decided to use a form. I have some sub-info too, but I can substitute a subreport in for that.

    Thanks for the link!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Happy to help. It sounds like a subreport would be part of the solution, which is not uncommon.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    Obviously I am doing something wrong, but I am not quite sure.

    Here is what I have done. I have a report that is a scouting form, basically its a page used for scouts when they go watch a basketball game, something to take notes on. Since the scout will be attending a game and scouting nearly 20 players a game, there is a need to be able to print all of the guys of a certain team with one click of a button (compared to going through each player's form and hitting print report).

    So I have a form setup with a Combo box, the combo box is named Team, so the combo box contains a long list of every University and College. To the right of the combo box is the Command button with the code you provided to me. Based on what is selected in the combo box and then with the push of a button, the Scouting Report should open up with just the players attending that school.

    However, when I click the button nothing happens.

    Here is what I am using: (Scouting Forms is the name of the Report)
    DoCmd.OpenReport "Scouting Forms", , , "School = " & Me.Team

    The link between the Player and School is actually based on an ID#. For instance, if you go to the table for the Players, the column school will be a number, not text.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    With that code, nothing will "open up". You haven't specified the mode, in which case the default is to print straight to the default printer (is anything printing?). I believe it's the argument right after the report name, but you can check in VBA help for OpenReport and make sure.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    Quote Originally Posted by pbaldy View Post
    With that code, nothing will "open up". You haven't specified the mode, in which case the default is to print straight to the default printer (is anything printing?). I believe it's the argument right after the report name, but you can check in VBA help for OpenReport and make sure.
    D'oh! I forgot to add the print command to it too. I'll check on that VBA help and get back with you. Thanks

  8. #8
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    I changed the view to acViewNormal.

    I'm getting Runtime Error 438. Object doesn't support this property or method.

    Another thing. Basically, my main goal here is that I'm filtering the players by their college. Of course, that is what the combo box is for on the Form with the Command Button. Now for the report that I want to open, which is filtered based on the college selected in the combo box, I have to have the College (aka School) as part of the Record Source, correct? What I have done temporarily is added a field to the Report which shows the player's school.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    You're wanting it to print straight out to the printer? I'd expect

    DoCmd.OpenReport "Scouting Forms", acViewPreview, , "School = " & Me.Team

    but it would help to see your current code. The field named "School" would have to be in the report's source, yes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    Below is a picture of the Macro. I was using VBA, but I thought maybe I could do the same here.




    Here is a snapshot of the Form with the command. The combo box has the label of Team. Whenever I click on the button now I get a box coming up that says Enter Parameter Value: Me.Team. These can be found near the bottom of the picture.
    Last edited by yes sir; 10-01-2010 at 06:46 PM. Reason: removed images

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    I don't use macros, but certainly the "Me" would cause a problem there. "Me" is only valid in VBA code. In the macro you'd have to use the full form reference:

    Forms!FormName.ControlName
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    Quote Originally Posted by pbaldy View Post
    I don't use macros, but certainly the "Me" would cause a problem there. "Me" is only valid in VBA code. In the macro you'd have to use the full form reference:

    Forms!FormName.ControlName

    Alright, I have it set to where it is printing reports, but it is printing all of the reports.


    I changed back over to VBA and this is the code I am using: (and I'm getting the run time error again)

    Private Sub Team_Click()
    DoCmd.OpenReport "Scouting Forms", acViewPreview, "School = " & Me.Team
    End Sub

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    You're missing a comma between acViewPreview and "School...". That puts it in the FilterName argument instead of the WhereCondition argument, which is looking for something different.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    yes sir is offline Competent Performer
    Windows Vista Access 2007
    Join Date
    Aug 2010
    Posts
    159
    Added the comma, same Run Time Error Message. The main connection between player and school is that the School's ID# is what goes in the Player's College column in the table for the Players. In my combo box for 'Team,' I have the ID for the colleges in the record source. Would the code be different if the data is a number compared to text? I think I'm in over my head here.



    Private Sub Team_Click()
    DoCmd.OpenReport "Scouting Forms", acViewPreview, , "School = " & Me.Team
    End Sub

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    That's the correct syntax for a numeric value. Is "Team" the name of the combo? Can you post the db?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Print Forms
    By Desstro in forum Forms
    Replies: 1
    Last Post: 09-04-2010, 02:23 AM
  2. Print preview with forms
    By jonesy29847 in forum Reports
    Replies: 4
    Last Post: 07-13-2010, 10:36 AM
  3. Replies: 8
    Last Post: 06-30-2010, 10:57 PM
  4. Creating User friendly Search Forms
    By BernardKane in forum Forms
    Replies: 7
    Last Post: 01-29-2010, 11:28 AM
  5. Help!!! user friendly forms/date entry
    By megank in forum Access
    Replies: 3
    Last Post: 03-31-2009, 09:47 AM

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