Results 1 to 8 of 8
  1. #1
    jhko is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2013
    Posts
    23

    Simple button on form (brain freeze!)

    Hi Gang:



    I've got a simple database. One table is employee names and IDs and a few other fields. Another related table lists review dates (there are many review dates per employee). I've set up a one to many relationship between the tables. I've also made a simple report that lists review dates.

    I've made a form to display the employee names and ID data. I have a button on that form. When I click the button, I want to go to the report that lists all the review dates, but display only review dates for the employee currently shown on the form.

    This is stupidly simple right? Can't I do it with a simple macro? For some reason I can't figure this out or get it to work- brain freeze!!

    I must be overlooking something really simple. I'd be very appreciative of any help.

    Many thanks in advance.

  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,652
    This would be one way:

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

    Macros do have the wherecondition argument too, though I think the syntax is different.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jhko is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2013
    Posts
    23
    Thanks very much Paul. I got this to work using your recommended line of code (instead of a macro, shown below), but now my report prints out by default upon clicking the button instead of just appearing on the screen. Is there a property or Access feature that controls this? I'd like to just show the report on the screen, not instantly print it.

    Private Sub Command36_Click()
    DoCmd.OpenReport "ReviewHistoryReport", , , "PayrollServiceID = " & Me.PayrollServiceID
    End Sub

  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,652
    Look in VBA help at OpenReport; you've left out the argument that controls print/preview.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jhko is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2013
    Posts
    23
    Thanks so much Paul, you got me looking in the right direction. Needs the acViewPreview (below). Now everything is working fine! BTW, I'm curious, why do you have to write "PayrollServiceID = " & Me.PayrollServiceID. Why not just "PayrollServiceID = Me.PayrollServiceID"? Why the & statement?


    Private Sub Command36_Click()
    DoCmd.OpenReport "ReviewHistoryReport", acViewPreview, , "PayrollServiceID = " & Me.PayrollServiceID
    End Sub

  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,652
    Happy to help. If you don't concatenate the value, you are passing the literal string

    "PayrollServiceID = Me.PayrollServiceID"

    instead of

    "PayrollServiceID = 123"

    to the report. The report can't evaluate the form reference, so it will fail. Concatenating values into strings is very common when working with SQL in VBA, and the wherecondition is basically SQL (it's defined as an SQL "WHERE" clause without the word WHERE).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jhko is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Feb 2013
    Posts
    23
    Thanks very much Paul. I'm slowly starting to get it. I'm beginning to know just slightly more about Access than a mature adult banana slug ;-).

    You've been great! I really appreciate the forum and your responses. As I get better, hopefully I'll be able to help others.

    Best Regards,

    Joe O.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help Joe, though I resent the comparison, being a mature adult banana slug myself. Okay, maybe I'm not that mature.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. simple email button
    By kpo in forum Forms
    Replies: 3
    Last Post: 05-30-2012, 02:50 PM
  2. Simple e-mail Button
    By jimmonator in forum Access
    Replies: 2
    Last Post: 10-13-2011, 02:47 PM
  3. Freeze Columns in a Form?
    By Paul H in forum Forms
    Replies: 9
    Last Post: 09-09-2011, 01:40 PM
  4. using VBA to freeze columns
    By bdaniel in forum Forms
    Replies: 1
    Last Post: 02-12-2010, 05:36 AM
  5. Simple delete button on form
    By chessico in forum Forms
    Replies: 9
    Last Post: 10-15-2009, 03:14 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