Results 1 to 6 of 6
  1. #1
    kaledev is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    20

    Question Passing param. to Report


    I have a report I am opening in VBA, and the report happens to be based off of a query that has two parameters (Start Date, and End Date). I am attempting to open the report with two variables I am sending via VBA.

    So far I have attempted...

    Code:
     
    strSDate = txtReportStartDate.Value
    strSDate = "Start Date = #" & txtReportEndDate.TEXT & "#"
    DoCmd.OpenReport "SUMMARY", acViewPreview, strSDate
    I know this is only attempting to send one parameter, but I have no idea how to send two. But the report seems to ignore what's being sent anyway, and still prompts me for the start date.

    Any help would be appreciated. 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,518
    For starters, you don't want to use the .Text property, as it requires focus. For two it would look like:

    "DateField Between #" & Me.txtReportStartDate & "# And #" & Me.txtReportEndDate & "#"

    If your field name has an inadvisable space in it, it will have to be bracketed:

    [Start Date]
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    kaledev is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    20
    Quote Originally Posted by pbaldy View Post
    For starters, you don't want to use the .Text property, as it requires focus. For two it would look like:

    "DateField Between #" & Me.txtReportStartDate & "# And #" & Me.txtReportEndDate & "#"

    If your field name has an inadvisable space in it, it will have to be bracketed:

    [Start Date]
    I am not exactly sure how I would integrate that into my code. Are you saying it should be:

    Code:
    strSDate = "[Start Date] = #" & Me.txtReportEndDate & "#"
    DoCmd.OpenReport "SUMMARY", acViewPreview, strSDate
    ..for one parameter? I still get prompted for the start date with that code. I have two parameters I would like to eventually send, but I'm not sure I understand that part of your code since I am prompted for both and it looks like your sending it as one parameter.

  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,518
    If you're getting a parameter prompt, something is likely misspelled, or that field isn't in the report's source. You can only have one wherecondition, but it can contain multiple parameters, separated by And/Or. You can also use Between, which I have. The example I gave is saying "give me all the records where the field named DateField is between the dates in the two textboxes".
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    kaledev is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2011
    Posts
    20
    Well the parameter is actually in the query that the report is pulling from, not the report itself. Does that make a difference?

  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,518
    It shouldn't, but you can put a textbox on the report for it and hide it to test.
    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. Passing value from one form to another
    By Molly152 in forum Forms
    Replies: 4
    Last Post: 11-16-2010, 11:03 AM
  2. Passing parameters to a query
    By stephenaa5 in forum Queries
    Replies: 3
    Last Post: 09-10-2010, 05:32 PM
  3. Passing a variable to a form
    By cjamps in forum Forms
    Replies: 0
    Last Post: 03-02-2009, 05:32 AM
  4. Passing Values
    By dromorkid in forum Forms
    Replies: 0
    Last Post: 11-25-2008, 05:04 PM
  5. Passing parameters to a report
    By elmousa68 in forum Access
    Replies: 0
    Last Post: 12-07-2006, 01:38 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