Hi All,
I have a table, tblCustomers, with fields SalutationID and Firstname.
I made a query, qrySelect = "Select FirstName from tblCustomers Where
SalutationID = [prmSalutationId]"
If I run this query by itself, it works fine. It asks me for the parameter
and then it shows the records . What I want is to be able to pass the
parameter to it in VBA
I am using the following code:
Dim stDocName as String
Dim db as Database
Dim qdf as QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("q rySelect")
qdf.Parameters["prmSalutationI d"] = 1
DoCmd.OpenQuery "qrySelect" , acNormal, acEdit
When I run this code, the query is asking for the parameter, as if I didn't
pass it.
I don't want to let the query pick the value of a component from the form
Any help appreciated
Regards,
Nicolae 3 47338
Nicolae, the reason it prompts you for the parameter is because you are
opening the query with your last statement. Instead, issue the
openrecordset method on the recordset object. Also, not sure, but think you
need parenthesis instead of brackets. Try this:
Dim stDocName as String
Dim db as Database
Dim rs as Recordset
Dim qdf as QueryDef
Set db = CurrentDb
Set qdf = db.QueryDefs("q rySelect")
qdf.Parameters( "Please enter a Salutations ID") = 1 'or a variable could be
used here
Set rs = qdf.OpenRecords et
Hope this helps.
--
Reggie
----------
"Nicolae Fieraru" <no****@please. cxm> wrote in message
news:41******** @duster.adelaid e.on.net... Hi All,
I have a table, tblCustomers, with fields SalutationID and Firstname. I made a query, qrySelect = "Select FirstName from tblCustomers Where SalutationID = [prmSalutationId]" If I run this query by itself, it works fine. It asks me for the parameter and then it shows the records . What I want is to be able to pass the parameter to it in VBA
I am using the following code:
Dim stDocName as String Dim db as Database Dim qdf as QueryDef
Set db = CurrentDb Set qdf = db.QueryDefs("q rySelect") qdf.Parameters["prmSalutationI d"] = 1
DoCmd.OpenQuery "qrySelect" , acNormal, acEdit
When I run this code, the query is asking for the parameter, as if I
didn't pass it. I don't want to let the query pick the value of a component from the form
Any help appreciated
Regards, Nicolae
Dear Reggie,
Thank you for your help. The brackets were a typo, I wrote the code in the
email and put by mistake brakets.
The qdf.OpenRecords et command works fine, but it doesn't open the query on
the screen. I need to view the results of the query on the screen.
Regards,
Nicolae
"Reggie" <No**********@N oSpamsmittysine t.com> wrote in message
news:Vc******** ************@co mcast.com... Nicolae, the reason it prompts you for the parameter is because you are opening the query with your last statement. Instead, issue the openrecordset method on the recordset object. Also, not sure, but think
you need parenthesis instead of brackets. Try this:
Dim stDocName as String Dim db as Database Dim rs as Recordset Dim qdf as QueryDef
Set db = CurrentDb Set qdf = db.QueryDefs("q rySelect")
qdf.Parameters( "Please enter a Salutations ID") = 1 'or a variable could
be used here
Set rs = qdf.OpenRecords et
Hope this helps.
-- Reggie
One way I know to do it is design 2 procedures in a standard module
something like this (got from
( http://www.mvps.org/access/queries/qry0005.htm)
Option Compare Database
Option Explicit
Public strname As String
Function SetValue(str As String)
strname = str
End Function
Function GetValue()
GetValue = strname
End Function
Now on click of button or whatever, pass a value to set the public variable
in the standard module. In your query on the criteria line of the field you
are filtering for type in =GetValue() and it will read the value you passed
to the SetValue function. Then it will open the query. Change the data
types as appopriate. What I have here opens my query showing me all records
where the fName field = Reggie. Hope this helps
Private Sub Command10_Click ()
Dim str As String
str = "Reggie"
Call SetValue(str)
DoCmd.OpenQuery "qry1", , acEdit
End Sub
--
Reggie
----------
"Nicolae Fieraru" <no****@please. cxm> wrote in message
news:41******** @duster.adelaid e.on.net... Dear Reggie,
Thank you for your help. The brackets were a typo, I wrote the code in the email and put by mistake brakets. The qdf.OpenRecords et command works fine, but it doesn't open the query on the screen. I need to view the results of the query on the screen.
Regards, Nicolae
"Reggie" <No**********@N oSpamsmittysine t.com> wrote in message news:Vc******** ************@co mcast.com... Nicolae, the reason it prompts you for the parameter is because you are opening the query with your last statement. Instead, issue the openrecordset method on the recordset object. Also, not sure, but think you need parenthesis instead of brackets. Try this:
Dim stDocName as String Dim db as Database Dim rs as Recordset Dim qdf as QueryDef
Set db = CurrentDb Set qdf = db.QueryDefs("q rySelect")
qdf.Parameters( "Please enter a Salutations ID") = 1 'or a variable
could be used here
Set rs = qdf.OpenRecords et
Hope this helps.
-- Reggie
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: WGW |
last post by:
Though I am a novice to MS SQL server (2000 I believe), I can do almost!
everything I need. Maybe not efficiently, but usefully. However, I have
a problem -- a complex query problem...
I can create a parameter query in a stored procedure, but how do I use
the result set of a parameter query in a select query (in the same or
another sp)? In short, if a select query contains a result table that is
generated as a parameter query, how do I...
|
by: Resant |
last post by:
I have a query :
Exec 'Select * From Receiving Where Code In (' + @pCode + ')'
@pCode will contain more than one string parameter, eg : A1, A2, A3
How can i write that parameters, I try use :
set @pCode='A1','A2','A3'
but get an error : Incorrect syntax near ','
|
by: MX1 |
last post by:
I'm ready to pull the hair out of my head. I have a query with a couple of
parameters that I want to get from combo boxes on a form. One parameter is
a date with a dynamically calculated year and the other is criteria for a
Yes or No field. I'll focus on the Yes/No field for simplicity.
If I run the query with the criteria hard coded as either "YES" or "NO", it
works.
In the values of the combo box in my form, I have it set as...
|
by: Zlatko Matić |
last post by:
Hi everybody!
Recently I was struggling with client/server issues in MS Access/PostgreSQL
combination.
Although Access is intuitive and easy to use desktop database solution, many
problems appear when someone is trying to use it as front-end for real
server database systems such as PostgreSQL or MySQL.
One of these problems is regarding pass-through queries and parameters.
I wanted to have all the code on client, while executing it on...
|
by: Mike Dinnis |
last post by:
Hi,
I've been working through a number of turorials to try to learn more about
retrieving data from a SQL database. I think i've mastered techniques where
i create a sql string in the page and pass it to the Db and retrieveing data
from a stored procedure, but I can't get the hang of parameters.
I have a method where I can get the parameters passed to the sp but it
doesn't want to return any results. Here's a copy of my code:
| |
by: owengoodhew |
last post by:
Guys I need your help/Advice...
In my Access Database I have a query (lets say qry1) and in this query
i have 2 fields for start and end date, which is provided by 2 Get
functions.
also i have qry2 based on qry1
then qry3 based on qry2
and finally qry4(using sql in code) based on qry3, and non of these 3
queries have the start and end date fields.
|
by: ShadesOfGrey |
last post by:
Hello again. Thanks to Gord, I have this cool query that puts my
student attendance records in a calendar format in Access 2003.
PARAMETERS Text ( 255 ), IEEEDouble;
TRANSFORM First(IIf(=1,"S","I")) AS Type
SELECT Year() AS , Month() AS , &
" " & AS Name
FROM Member_List_tbl INNER JOIN Attendance_tbl ON Member_List_tbl. = Attendance_tbl.
WHERE ((( & " " & )=) AND
((DatePart("yyyy",))=))
|
by: kennthompson |
last post by:
Trouble passing mysql table name in php. If I use an existing table
name already defined everything works fine as the following script
illustrates.
<?php
function fms_get_info()
{
$result = mysql_query("select * from $tableInfo") ;
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
|
by: vksundari |
last post by:
I am executing a select query in a C# component and populating a ASP Grid in Search.aspx.
Now one of the columns in the Grid in Search.aspx is Policy Number(hyper link)
Basicallly I want to call a ASP.net method by sending parameters from that link.
For example
Select a, b, policy_number from x
Policy_Number is the hyperlink.
Now I want to call a ASP.net method sending in a and b as input parameters.
|
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...
|
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,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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...
| |