Results 1 to 2 of 2
  1. #1
    Desmondo is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Mar 2012
    Location
    Gold Coast, Australia
    Posts
    6

    VBA to open report from form

    In the past I have always used macros but am trying to break the habit and have got stuck. I have searched and searched but must be missing something. I am trying to open a report from a button on a form however, the report shows all records not the one I am trying to specify with the [ID_Student] primary key. Heres the code I have;

    stLinkCriteria = "[ID_Student]=" & Me![ID_Student]


    DoCmd.OpenReport "r-StudentProfile", acViewPreview, , , , "[ID_Student]=" & Me![ID_Student]

    Any help would be appreciated.

    *I found the problem, right after posting this... to many commas after acViewPreview,, should have only been 2. Being a VBA newbie perhaps someone could explain the significance of the commas, cheers.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Each comma separates an argument of the OpenReport method. Some arguments are required, such as the report name. For others, if no argument provided, default will be applied. The WHERE CONDITION argument is the 4th argument in the sequence, therefore 3 commas.

    This convention will be applicable to many function and method calls.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Open report from data entry form
    By pbuecken in forum Forms
    Replies: 5
    Last Post: 01-14-2012, 12:07 PM
  2. Open Current Report With Form Button
    By Rick5150 in forum Reports
    Replies: 8
    Last Post: 10-12-2011, 02:28 PM
  3. Open Report with Form
    By TinaCa in forum Programming
    Replies: 7
    Last Post: 09-06-2011, 04:38 PM
  4. Open Report or Form depending on condition
    By jheintz57 in forum Forms
    Replies: 5
    Last Post: 03-12-2010, 08:16 PM
  5. open report from a vb form
    By tracamonali in forum Reports
    Replies: 2
    Last Post: 08-10-2009, 01:55 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