2 days ago: Power and Internet are out in my office due to Hurricane Ian. Click for details.
 
Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Seminars   Templates   TechHelp   Fast Tips   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 
11 days 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
11 days 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
11 days 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
    r.MoveFirst
    Do While Not r.EOF
        MsgBox r!country_name
        r.MoveNext
    Loop
    r.Close
    q.Close
End Sub
Kevin Yip
11 days ago

Kevin Yip
11 days 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
11 days ago

Richard Rost
4 days ago
I'd usually "store" it on an open form field. See Value From a Form.
Add a ReplyUpload an Image


Back to Access Forum Comments
 

Start a NEW Conversation
 
Only students may post right now. Click here for more information on how you can set up an account. If you are a student, please LOG ON first.
 
Subscribe
 

Check out these other pages that may be of interest to you:

9/27/2022Report Border
9/26/2022First Day of Month
9/23/2022Before Update
9/22/2022Synchronize Subforms
9/21/2022InputBox
9/20/2022Link Master Fields
9/19/2022DateSerial
9/18/2022Sequential Annual Coding
9/16/2022Scope
9/15/2022Resize Forms
 
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Email Richard
Mailing Address
Phone Number
Fax Number
Course Survey
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn