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 
2 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
2 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
2 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
    r.MoveFirst
    Do While Not r.EOF
        MsgBox r!country_name
        r.MoveNext
    Loop
    r.Close
    q.Close
End Sub
Kevin Yip
2 months ago

Kevin Yip
2 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
2 months ago

Richard Rost
2 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
Subscribe to Access Forum
Get notifications when this page is updated
 
 

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

11/25/2022Application Title
11/24/2022Full HTML Editor in Access
11/24/2022Change Database Title
11/23/2022Other Names
11/21/2022Check Icon File
11/21/2022Check Icon File
11/18/2022Archive Records
11/17/2022InStr Function
11/16/2022Numbers As Text
11/15/2022Merge Tables
 
 

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

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
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
amicron@gmail.com
Blog RSS Feed    Twitter

YouTube Channel    LinkedIn