Free Lessons
Fast Tips
Topic Index
Home   Courses   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
Home > Forums > Access
Access Forum

Back to Access Forum

How to store a parameter value Upload Images   Link  
John Hirschy 
15 months ago
I am writing code where I use a parameter value in a query.  I would like to store that parameter value for later use in my coding.  How do I store the parameter value?
Scott Axton
15 months ago

Sorry to be a bit vague, but the answer to your question is "it depends".
The method you use kind of depends on how long you want to save that value for.  Just for that procedure, across multiple procedures, from session to session?

There are Variables , TempVar (not covered well here yet but we're nagging Richard), Global Variables.  See: Scope

If you need the value to survive between sessions you could write it to a settings table and read it back in again in the next session or when the need for that value arrises.

If you can explain a bit about what your needs are we can help you further.
Kevin Yip
15 months ago
You have to use VBA to store the parameter in a variable.  To use the parameter again for the query, you need to run the query with VBA as well.  The sample code shows how to run such a query.  The picture below shows how the query looks in query design.  The parameter is called "Country name contains", and note how it is used in VBA.

Sub RunQueryWithParameter()
    Dim q As QueryDef, r As Recordset
    Set q = CurrentDB.QueryDefs("Query: Countries")
    q.Parameters("Country name contains") = "united"
    Set r = q.OpenRecordset
    Do While Not r.EOF
        MsgBox r!country_name
End Sub
Kevin Yip
15 months ago

Kevin Yip
15 months ago
The line  q.Parameters("Country name contains") = "united"  serves the same purpose as typing "united" as the parameter when you run the query manually (see pic below).
Kevin Yip
15 months ago

Richard Rost
15 months ago
I'd usually "store" it on an open form field. See Value From a Form.

This thread is now closed. If you wish to comment, start a NEW discussion, below.

Back to Access Forum Comments

Start a NEW Conversation
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
Subscribe to Access Forum
Get notifications when this page is updated

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.

Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
My Account
My Courses
Lost Password
Student Databases
Change Email
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Customer Support
Web Site Tour
Consulting Services
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Video Tutorials
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Terms of Sale
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

Copyright 2023 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 12/8/2023 2:42:52 PM.