Results 1 to 4 of 4
  1. #1
    reburton is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2013
    Posts
    14

    Passing parameters

    I am trying to pass a parameter to a query and it won't take it. I am using this line to do it: DoCmd.SetParameter "[Last Date]", StrDate


    Where strDate is the variable in string form. I have tried using a date value and neither affects the query at all. It just ignores it. If I run the query from the access interface it accepts the parameter when I type it in. Am I doing something wrong?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by reburton View Post
    I am trying to pass a parameter to a query......
    I've not heard of this before. Can you explain a bit more about what you are actually trying to do.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    reburton is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Oct 2013
    Posts
    14
    I am trying to run some queries that all have a parameter asking for a date. The date comes from another query's results. I tried to figure out how to get the date directly from the query but I don't know enough about SQL to do the job. Then I tried to do it from VBA (I was writing a sub to run the queries anyway.). I found this line of code somewhere and tried to apply it, but it doesn't seem to work. Someone suggested that I put it in a form and have the queries get it there, but again I don't know enough SQL to do that either. I'm obviously very new to this.

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    IMHO queries should be used to delete, update and retrieve data. Viewing that data should be done with reports and forms. A parameter query is just a select query that requests some criteria when it runs. This request for criteria could be replaced with an expression that gets the input from a control (probably a text box) on an open form.
    So, what you could do is this:
    The date comes from another query's results.
    Create a form to display this data. Let’s call this form frmOriginalData.


    I am trying to run some queries that all have a parameter asking for a date
    Create a form to display this data. Let’s call this form frmParamQry. In the query for this form, replace the criteria with an expression that references the control on frmOriginalData, that has the value that had been required for the parameter query. This will be some thing like:
    Forms!frmOriginalData.NameOfControl
    Now create a button on the form called frmOriginalData that opens the form called frmParamQry. The code for this button would be:
    DoCmd.OpenForm " frmParamQry "
    I would actually remove the criteria from the query for the form called frmParamQry and set the criteria with the line of code that opens the form. Something like:
    DoCmd.OpenForm "Form1", , , [YourDateField] = #“ & FormControlName & “#”
    The # signs are required as the data is a date.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

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

Similar Threads

  1. passing parameters to a query
    By PatrickCairns in forum Programming
    Replies: 1
    Last Post: 12-11-2012, 08:47 PM
  2. Passing parameters into vb using access query
    By markyboy171 in forum Programming
    Replies: 4
    Last Post: 06-15-2012, 05:46 AM
  3. Passing parameters from a form
    By rfs in forum Forms
    Replies: 1
    Last Post: 03-15-2011, 12:25 AM
  4. Passing parameters to a query
    By stephenaa5 in forum Queries
    Replies: 3
    Last Post: 09-10-2010, 05:32 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