473,387 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to Run Parameter Query in VBA???

132 100+
Hi all!!
I have a simple database with 56-Queries that runs by passing parameters from specific forms. It works perfect!!!
The problem is, I`m running out of space in the navigation pane, with 56 queries and more parameter queries to come.
I would like to build parameter query in VBA so as to have user friendly database using the following code!
Expand|Select|Wrap|Line Numbers
  1. Private sub parameterquery()
  2. Dim stringSQL As DAO.Workspace   'Current workspace (for transaction).
  3.   Dim db As DAO.Database    'Inside the transaction.
  4.   Dim bInTrans As Boolean   'Flag that transaction is active.
  5.   Dim stringSql11 As String      'Action query statements.
  6.     Dim strMsg As String      'MsgBox message.
  7.     'Step 1: Initialize database object inside a transaction.
  8.   Set stringSQL = DBEngine(0)
  9.   stringSQL.BeginTrans
  10.   bInTrans = True
  11.   Set db = stringSQL(0)
  12. stringSql11 = "Delete tblMytableName.Field1, tblMytableName.Field2, tblMytableName.Field3 FROM tblMytableName WHERE (((tblMytableName.Field1)=Me![FormsField1]));"
  13. db.Execute stringSql11, dbFailOnError
  14. stringSQL.CommitTrans
  15. End Sub
  16.  
when running this code, it gives RunTime error 3061 "Too Few Parameters Expected 1"
Where am I doing Wrong???
Please help!!!!!
Dec 23 '11 #1
8 2525
NeoPa
32,556 Expert Mod 16PB
Your SQL is invalid. It refers to Me, which only has a meaning within report or form object modules - not in SQL.

Also, please read How to Debug SQL String so you know how to post such questions in future.
Dec 23 '11 #2
Rabbit
12,516 Expert Mod 8TB
What are these 56 queries? I suspect they are similar with a slight change.
Dec 23 '11 #3
Mr Key
132 100+
Thanks Neo and Rabbit, the queries runs with respect to the forms, the key word Me refers to the current Fields in a forms that referenced by the query. May be it is not the right place to be thus why I have asked for your hint!!!
Rabbit, these queries varies in structures and differ one another; I have Append queries, Delete Queries, Update queries and simple queries, but all of them runs with parameters taken from either FormsComboBox or formstextBox.
The programs is running perfectly but I want to improve by adding more queries and thus am running out of space in the navigation pane and is very hard to spot the query in the pane.
Please help!!!
Dec 24 '11 #4
NeoPa
32,556 Expert Mod 16PB
Mr Key:
May be it is not the right place to be thus why I have asked for your hint!!!
Indeed. But when I gave you a hint (two in fact) you seem to have ignored it (them).

Reading the linked article and following the instructions there will help to save you wasting so much time on things which are easily handled by following those instructions. From there, we might have something a little more sensible to work with than VBA code that creates what you think ought to be SQL.
Dec 24 '11 #5
Mr Key
132 100+
Ok thanks NeoPa!
You always have constructive ideas but very hard to grasp!!!
I have read the article as suggested but coldnt solve my problem.
I have a parameter query which is working properly so far, I just want to change the design towards VBA from ordinary queries. Should I run my first SQL through VBA then I can go ahead debugging my SQL string!!!!
You know, I can make it on my own should there be no choice behind but it might take longer than under your assistance or hint!
Dec 26 '11 #6
NeoPa
32,556 Expert Mod 16PB
The first thing I'd do, if I were you, would be to use the linked article to get the exact contents of the SQL string immediately prior to execution posted here in this thread. That way we are looking directly at the SQL and don't need to get ourselves confused with VBA things.
Dec 27 '11 #7
Mihail
759 512MB
Hi !
Mr Key take a look here. Maybe this is also an answer for you:
http://bytes.com/topic/access/answer...y-filter-query
Dec 27 '11 #8
Mr Key
132 100+
Thanks Mihal and Neopa for your time!
I will work it out for two days and post the answer right here!
Dec 27 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: MX1 | last post by:
Simpler way to ask question from my previous post. I wrote a query and it has a paramter field in it. I want to enter a date with the current year. If it I put in 6/30/2003, it works great. If I...
1
by: Cory | last post by:
When I run the subroutine testEmailContacts the msgbox says that there is only 1 record. The sql for qyEmailContactsQyCard is below. There is over 3000 records in the table "tbl:Contact". What am i...
2
by: Julie Wardlow | last post by:
Help! I am calculating a future date using the DateAdd function in a query (the calculation also involves an IIf statement), and have managed to get this formula to produce the required result....
1
by: carrionk | last post by:
Hi, I have created a Subform which SourceObject is a parameter query. This is the Query: Qry Name:80IsscomProduct SELECT * FROM Isscomp28 WHERE Like ;
1
by: john_stivenson | last post by:
I have a subform whose source is a parameter query. How can I programatically change query parameters and refresh subform without showing "Enter Parameter Value" dialog?
0
by: AP | last post by:
I use the following snippet to open a build a querydef. This works great with a query that has a parameter that points to a form, but if I try to use it in a parameter query, even if the parameter...
1
by: jmarr02s | last post by:
When I double click on my form..I get a Parameter Query box. How can I turn this off?! I went to properties, but did not see anything that would help remove this. I also deleted the query...
3
by: limperger | last post by:
Hello everyone: This question is neither urgent nor important, but I post it just in case anyone knows (and wants to give a reply, of course XD). I have little idea of VBA, but I have dared to...
4
by: chicane | last post by:
I am currently writing a query in Access. I need to set up a parameter query for three fields which are called Status (text field), Authorised (date field) and Legal notices (date field). I need...
2
by: brat33 | last post by:
I am trying to modify some code to create a mail merged label document within Word 2007, using a Access 2007 Parameter Field. My issue comes about when I cannot see the Parameter Query within the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.