Results 1 to 4 of 4
  1. #1
    Lori F is offline Novice
    Windows 11 Access 2019
    Join Date
    Jan 2024
    Posts
    12

    Passing a column from a table as a parameter into a macro for use in a query

    I have a BegEndDates table with only 1 record in it. It is used to hold a month and a year field so that I don't have to enter it every time I run specific queries. I change those 2 fields once a month. I have a query that finds records from another table called Transactions based on specific criteria. Some of that criteria is based on fields in the Transactions table. I also need to select only records where the date in the transactions table is equal to the month and year in the Beg End Dates table. When I pull both tables into the same query, I can no longer edit data in the datasheet view as I need to. If I simply put 2 parameters into the query and don't call the BegEndDates table, I'm able to make changes to the data as needed, but I'm forced to enter the month and year every time I open the query.


    I was hoping to run the query in a macro and hopefully somehow pass the month and year from Beg End Dates into the parameters of my Transactions query so that I can then edit data as needed.

    I want to take my query that asks for the month and year to match my transaction date without having to enter the month and year and retrieve it from that other table without that table being in the query. I hope that makes sense. Below, I show an example of my query with the parameters. This is the only way it allows me to make changes to data in the datasheet view. The second screen shot brings in the data, but I can no longer make changes to the data in the datasheet view. Is there a way to pass that data into the query in a macro so that I can run it multiple times a month without entering the parameters each time and still be able to edit data when needed?
    Attached Files Attached Files

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Try this:
    Click image for larger version. 

Name:	query.png 
Views:	17 
Size:	15.8 KB 
ID:	51393

    I changed some field names, as Name and Type are Access reserved words. Best to avoid reserved words.
    Also, you seem to have arbitrary spaces in field names. It's best to not have spaces at all. Or special characters. Fuel/Mileage could be interpreted as fuel divided by mileage.
    Click image for larger version. 

Name:	spaces.png 
Views:	17 
Size:	26.8 KB 
ID:	51394
    Last edited by davegri; 01-27-2024 at 07:49 PM. Reason: more advice

  3. #3
    Lori F is offline Novice
    Windows 11 Access 2019
    Join Date
    Jan 2024
    Posts
    12
    Thank you so much for those screen shots. I also appreciate the suggestions. I made the dlookup changes that you suggested, and it worked great! Thanks so much for your help. Have a blessed day.

  4. #4
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Happy to help. Good luck with your continuing project!

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. Replies: 5
    Last Post: 10-09-2015, 09:27 AM
  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. Macro passing a parameter
    By SlowPoke in forum Access
    Replies: 1
    Last Post: 09-26-2010, 09:57 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