Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6659227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:00:31+00:00 2026-05-26T02:00:31+00:00

I have an SQL query which takes up a parameter stored in the db.

  • 0

I have an SQL query which takes up a parameter stored in the db. I want to invoke the same from VBA code which is running on the same db. I am using MS Access for my work.

So for example consider, I have an SQL query ‘Q’ which takes a parameter ‘p’, I intend to invoke this SQL query from my VBA code ‘C’ , which also naturally involves passing this parameter ‘p’ to the query.

Help much appreciated
Soham

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:00:32+00:00Added an answer on May 26, 2026 at 2:00 am

    There are a few possibilities here.

    Let us say it is a SELECT query built on a form that holds the parameters to be used and that the input is safe:

    s = "SELECT * FROM MyTable WHERE AText ='" & Me.MyText & "'"
    

    This can be used like so:

    Forms!SomeForm.RecordSource = s
    

    Or

    Set qdf = CurrentDb.CreateQueryDef("NewQuery", s)
    

    However, the above can be done in other, better ways.

    Let us say it is a ACTION query run from a form that holds the parameters to be used and that the input is safe:

    s = "UPDATE MyTable Set AText ='" & Me.MyText & "'"
    

    Then

    Set db = CurrentDB
    db.Execute s, dbFailOnError
    

    Or you can use a temporary query, which can be safer:

    'Temporary query
    s = "UPDATE MyTable Set AText = MyRext"
    
    Set qdf = db.CreateQueryDef("", s)
    
    qdf.Parameters!MyText = Me.MyText
    qdf.ReturnsRecords = False
    qdf.Execute dbFailOnError
    

    Something similar to the above would also be suitable for an existing query.

    You can also pass the parameter to a procedure, in which case Me.MyText becomes a variable, or you can use Inputbox, which is rarely a good idea.

    After that, there is the whole world of ADO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following which works in SQL Query Analyzer . select oh.* from
I have a class DBHandler which takes a query, runs it through the SQL
hey guys, i have a query in sql server which takes atleast 10-15 seconds
I have created a stored procedure in SQL Server, which runs immediately from Management
I have a query which I'm using with SQL Server 2008R2 via ADO.NET. When
I have a class which takes an SQL query, executes it, then binds every
I have a SQL query which is written in string and then executed using
I have a sql query which takes longer than 30seconds to execute. I'm aware
Can we have a SQL query which will basically help in viewing table and
Right now I have this SQL query which is valid but always times out:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.