473,883 Members | 1,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to use Function to pass query parameter?

I need a way to create a table with a programmaticall y defined name. I have a
Make Table query that will create the table with the name that I put in the
query, but I don't know how to (or if I can) use a function to pass the table
name into the query.

Here is the basic form of the Mke Tble query:

SELECT TxDate, Amount, Tx_ID, TxAcctName, INTO [table name here] FROM
tblTxJournal;

This does not seem to work:

SELECT TxDate, Amount, Tx_ID, TxAcctName, INTO (QryPrmName) FROM
tblTxJournal;

Public Function QryPrmName() As String
Dim strTxAcct As String
Dim strQtr As String
Dim strYr As String
strTxAcct = Forms!frm2!cbx2 TxAcct.Column(1 )
strQtr = Forms!frm2!cbx2 Quarter.Column( 1)
strYr = Forms!frm2!cbx2 Year
QryPrmName = "Transactions_F or_" & strTxAcct & "_" & strQtr & "_" & strYr
End Function

Is it possible to do this?

Thanks in advance.
Nov 12 '05
15 7207
> Well, it's the name of the table or the query if you export a query. You
could create a named querydef, set the SQL to SELECT * FROM <table-name>, then
export the querydef. That's much more efficient than copying all the data to
a new table, and is actually a bit simpler to code.


Okay, how about this:

Private Sub cmdExportTx_Cli ck()
Dim strTitle As String
strTitle = FunctionTitle 'puts a string together
Call TxNew(strTitle)
DoCmd.OutputTo acOutputQuery, strTitle, , , True
DoCmd.DeleteObj ect acQuery, strTitle
End Sub

Create query here:

Private Sub TxNew(strTitle As String)
Dim strSql As String
Dim qdf As QueryDef
Dim db As DAO.Database
strSql = "SELECT ... QryPrm("Form", "Control") ... "
Set db = CurrentDb
Set qdf = db.CreateQueryD ef(strTitle, strSql)
Set qdf = Nothing
Set db = Nothing
End Sub

Handle query parameters here:

Public Function QryPrm(ByVal strFrm _
As String, ByVal strCtl As String) As Variant
QryPrm = Forms(strFrm).C ontrols(strCtl)
End Function

No more table... but still need to use DoCmd to delete the query. Still, I
agree this is better...
Nov 12 '05 #11
On Sun, 01 Feb 2004 22:53:54 GMT, "deko" <dj****@hotmail .com> wrote:
Well, it's the name of the table or the query if you export a query. You
could create a named querydef, set the SQL to SELECT * FROM <table-name>, then
export the querydef. That's much more efficient than copying all the data to
a new table, and is actually a bit simpler to code.


Okay, how about this:

Private Sub cmdExportTx_Cli ck()
Dim strTitle As String
strTitle = FunctionTitle 'puts a string together
Call TxNew(strTitle)
DoCmd.OutputTo acOutputQuery, strTitle, , , True
DoCmd.DeleteObj ect acQuery, strTitle
End Sub

Create query here:

Private Sub TxNew(strTitle As String)
Dim strSql As String
Dim qdf As QueryDef
Dim db As DAO.Database
strSql = "SELECT ... QryPrm("Form", "Control") ... "
Set db = CurrentDb
Set qdf = db.CreateQueryD ef(strTitle, strSql)
Set qdf = Nothing
Set db = Nothing
End Sub

Handle query parameters here:

Public Function QryPrm(ByVal strFrm _
As String, ByVal strCtl As String) As Variant
QryPrm = Forms(strFrm).C ontrols(strCtl)
End Function

No more table... but still need to use DoCmd to delete the query. Still, I
agree this is better...


Yup - this looks pretty good. Of course (even though I suggested this) it's
still a kludge. The best possible way would be to use the Windows API to open
the file selector, supply the default name yourself to the API call, then use
the file name the user selected in the OutputTo. What you have now is decent,
though.
Nov 12 '05 #12
why not just leave the temporary query there and just assign a new SQL
statement to it?
Nov 12 '05 #13
> why not just leave the temporary query there and just assign a new SQL
statement to it?


How do I do that?


Nov 12 '05 #14
> Yup - this looks pretty good. Of course (even though I suggested this) it's
still a kludge. The best possible way would be to use the Windows API to open
the file selector, supply the default name yourself to the API call, then use
the file name the user selected in the OutputTo. What you have now is decent,
though.


appears to work great. only problem is now I want to recode other queries to
work like this... entering infinite loop of rewrite :-P

Thanks for the help.
Nov 12 '05 #15
On Mon, 02 Feb 2004 04:52:54 GMT, "deko" <dj****@hotmail .com> wrote:
Yup - this looks pretty good. Of course (even though I suggested this) it's
still a kludge. The best possible way would be to use the Windows API to open
the file selector, supply the default name yourself to the API call, then use
the file name the user selected in the OutputTo. What you have now is decent,
though.


appears to work great. only problem is now I want to recode other queries to
work like this... entering infinite loop of rewrite :-P

Thanks for the help.


I'm not sure what you were saying with that last paragraph. It sounds like
you might have a case here where you should refactor some things so that
if/when you change your approach, you only have to change code one place.
Then you can use the named query approach for now, since you know it's
working, and improve the code later if the need arises by changing just one or
2 centralized functions.

The earlier you can identify and remove duplication, the more time it will
save you down the road.
Nov 12 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2743
by: | last post by:
From ASP I run a query using MIN(some_field/parameter) Now I need to pass this parameter to the query from ASP code How do I do that? Syntax like MIN( / ) does not work
5
14047
by: Belinda | last post by:
Hello All I have the following test.asp page which needs one parameter querystr but my querystr is a very long string value. When I send a long value the query string is getting truncated after some characters. Can you please kindly share the code segment to workaround how to pass such a long string value to a asp page. This is how I invoke the test page:
13
3506
by: Maroon | last post by:
Hi, I want to write a standard java user defined function, like this example:- select db_fun("roll"), roll from student; **db_fun() will work for all tables of the all databse here db_fun is the function that i want to write. The student table is:- roll name 1 'A'
5
13236
by: Don Seckler | last post by:
I have an update query that runs when a report closes. I have several reports that will need to run the update query with diferent criteria. I'd like to simply make the criteria change in the report vba instead of making different queries. Here's my query sql: UPDATE Draw SET Draw.Billed = Yes WHERE (((Draw.Billed)=No) AND ((Draw.WholesalerName)="Hudson"));
7
21652
by: Zlatko Matiæ | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the server ? Is it possible to use parameters in pass-through queries ? An additional question: Is it possible to connect to a database on MySQL or PostgreSQL using ADO ? Is it possible to execute pass-through queries with parameters, using ADO...
23
1785
by: Neil | last post by:
I have an Access 2000 MDB file with a SQL 7 back end. I have a main table with 50,000 records; and I have a selections table with 50,000 records for each machine that uses the database (about 25-50). This allows each user to have their own set of selections. The selections table has three fields: ID (int), Sel (bit), MachName (varchar). ID and MachName comprise the primary key. I have a view that combines the main table and the entries...
9
2324
by: Alan Silver | last post by:
Hello, I'm a bit surprised at the amount of boilerplate code required to do standard data access in .NET and was looking for a way to improve matters. In Classic ASP, I used to have a common function that was included in all pages that took an SQL query and returned a disconnected recordset. This meant that data access could be achieved in a single line. I would like to do something similar in ASP.NET. I know I could just duplicate...
1
7763
by: | last post by:
Hi, I've defined an ObjectDataSource and a parameterized DataSet. I would like it if I could pass the parameter value that describes the query that creates the DataSet as part of a user control declaration. Here's how the parameter is described in the context of my ObjectDataSource: <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetArticlesByWhomever" TypeName="WhateverTableAdapters.WhateverTableAdapter">
0
2201
by: alpha122 | last post by:
I am beginner and I need some help writing simple perl script. I need to get url query and pass it to the javascript function as parameter. for example: my page will be http://myhomepage.html?var1=test1&var2=test2.. These variable could be anything that is entered by user. Now I need to get these variables an pass those values in my javascript function as parameter. Thanks in advance for help..
0
9942
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11142
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10745
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10848
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9575
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7972
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7130
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3234
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.