Results 1 to 10 of 10
  1. #1
    bcournoyer is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2023
    Posts
    9

    Passing a Clicked Field value as a parameter to a Query

    I have a tablular form with one of the fields being value I want to use to constrain the query for the new form opened. In the Macro in the OpenForm action I can call for the value of a form field via [Forms]![formname]![fieldname]. I tried this, but doesn't seem to use the clicked field's value. What am I missing?

    Here's what I am trying to do. I have a tablular form that shows a number of sales orders. I want to click on the desired sales order number and display that info in a new form using the following macro.

    Click image for larger version. 

Name:	query.png 
Views:	16 
Size:	7.4 KB 
ID:	50955




    ORDERNO exists as a field in both tables.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps you need to save the record before referencing a control/field that is dirty
    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
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    You mention "macro" but show what looks like vba and they are not the same. I can find nothing in the entire list of macro command that would allow you do do this.
    So if in fact this is about code, then my guess is that the field is a lookup field in your table. You should explain what is meant by not using the clicked field value. What value does it use and what value do you expect it to use.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    bcournoyer is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2023
    Posts
    9
    Micron, I modified the post with more info.

    Thx

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Thanks, but still don't know if we're dealing with a table lookup field or what value is being returned. While I'm at it, I might as well add to the list: is the control on a subform or a form on a navigation form?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    bcournoyer is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2023
    Posts
    9
    Thanks for the questions Micron. My novice tag is showing. The form I'm selecting the field from is a form called by a button that constrains the data to a specific customer name. The form was created as a tabular form through the form wizard. Do you want to see the OpenForm macro associated with populating this form?
    Click image for larger version. 

Name:	SalesOrderList.png 
Views:	15 
Size:	20.3 KB 
ID:	50956
    Clicking on the OrderNo field will open a new form referencing the same table but displaying info constrained by that order number. It instead returns data for all the order numbers.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    In 2007, there is no need for the first = ?
    Is the form control called OrderNo?

    Honestly start learning VBA, so much easier, neater and easier to debug.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    bcournoyer is offline Novice
    Windows 10 Office 365
    Join Date
    Oct 2023
    Posts
    9
    Yeah, I'm think VBA will be the way to go.

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Well the OpenForm macro is pretty much the same as the VBA version, but so much easier to debug.
    I tried your method on a form and used a hardcoded value and a form control reference and they both worked.?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Maybe it would help to see the macro steps that open the form. Or you could copy, compact/repair it, zip it and post the file here. Not many db's will be under the 500kb limit for uploading files. See How to Attach files at the top of the page if you need help.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Passing a query parameter to a report
    By clancy76 in forum Access
    Replies: 3
    Last Post: 07-02-2020, 03:25 PM
  2. Passing values from a Form to a Parameter Query
    By wizzz_wizzz in forum Access
    Replies: 5
    Last Post: 02-28-2017, 08:43 PM
  3. Passing parameter from form to query
    By rhubarb in forum Forms
    Replies: 3
    Last Post: 05-03-2015, 10:29 AM
  4. Passing textbox value into sql query parameter
    By gustavoavila in forum Access
    Replies: 7
    Last Post: 04-23-2014, 04:00 PM
  5. Replies: 2
    Last Post: 05-06-2012, 03:52 PM

Tags for this Thread

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