473,486 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to pass the value of a public variable to a named query as parameter

2 New Member
I have a form that has a subform to ask/assign a value (inserted by the user) to a public variable (VB).
The same form has an Option Group that lauches named querys using DoCmd.OpenQuery.
How can I pass the value held in my public variable to the query as a parameter ? The query has a "where" clause that should "understand" the value inserted by the user on my form.
Can anybody help me ?
Sep 12 '07 #1
3 1618
JKing
1,206 Recognized Expert Top Contributor
Hi there,

I think a better route overall maybe to create reports based off your queries. Except remove the portion of the where clause that equates the user entered value.

Using the Docmd.OpenReport command you can specify the rest of the where statement.

Here's an example of using the Where Condition parameter of the openreport command.

Let's assume we have a report based off this simple query for a book catalogue.

Expand|Select|Wrap|Line Numbers
  1. SELECT bookID, bookName, bookAuthor, bookLength, bookCoverType
  2. FROM tblBook
  3.  
Expand|Select|Wrap|Line Numbers
  1.  Docmd.OpenReport "rptBookListing", acViewNormal,, "[bookAuthor] = 'Jared'",acWindowNormal 
  2.  
If you don't want to make reports you can include form fields as part of a where clause.

Let's use the same query as above mention and add a where clause that will be based off the textbox off a form.

Expand|Select|Wrap|Line Numbers
  1. SELECT bookID, bookName, bookAuthor, bookLength, bookCoverType
  2. FROM tblBook
  3. WHERE bookAuthor = Forms!frmBook!txtAuthor
  4.  
Forms is the collection of open forms.
frmBook is the name of your form
txtAuthor would be a control on your form i.e. a text box
Sep 12 '07 #2
dsalex
2 New Member
Hi there,

I think a better route overall maybe to create reports based off your queries. Except remove the portion of the where clause that equates the user entered value.

Using the Docmd.OpenReport command you can specify the rest of the where statement.

Here's an example of using the Where Condition parameter of the openreport command.

Let's assume we have a report based off this simple query for a book catalogue.

Expand|Select|Wrap|Line Numbers
  1. SELECT bookID, bookName, bookAuthor, bookLength, bookCoverType
  2. FROM tblBook
  3.  
Expand|Select|Wrap|Line Numbers
  1.  Docmd.OpenReport "rptBookListing", acViewNormal,, "[bookAuthor] = 'Jared'",acWindowNormal 
  2.  
If you don't want to make reports you can include form fields as part of a where clause.

Let's use the same query as above mention and add a where clause that will be based off the textbox off a form.

Expand|Select|Wrap|Line Numbers
  1. SELECT bookID, bookName, bookAuthor, bookLength, bookCoverType
  2. FROM tblBook
  3. WHERE bookAuthor = Forms!frmBook!txtAuthor
  4.  
Forms is the collection of open forms.
frmBook is the name of your form
txtAuthor would be a control on your form i.e. a text box

My "named querys" have to manipulate data (insert/update) not just recall ... so ... reports are not proper ... :-(
Thanks anyway
Sep 13 '07 #3
JKing
1,206 Recognized Expert Top Contributor
Did you read the bottom part of my previous post that explains how to reference controls in a query?

Also you can write action queries on the fly and run them in VB. If you provide an example of one of your queries and the control/variable you're trying to use, I'm sure we could work something out for you.
Sep 13 '07 #4

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

Similar topics

4
14216
by: Corey | last post by:
All, I am relatively new to XML and I have what may sound like a dumb question. I want to pass a query string variable to my xml document and filter the output based on that variable. For...
5
11022
by: deko | last post by:
I'd like to use a bit of code in the OnOpen event of a report: =rptOpen(Me.ReportName), (Me.Tag) --this doesn't work This does work: Private Sub Report_Open(Cancel As Integer)...
5
1537
by: Javier Campos | last post by:
WARNING: This is an HTML post, for the sake of readability, if your client can see HTML posts, do it, it doesn't contain any script or virus :-) I can reformat a non-HTML post if you want me to (and...
4
3391
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then...
9
2303
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...
2
19756
by: phil | last post by:
Hi, I want to put a recordset in a gridview but i don't know how to pass the value of the variable in the 'where' statement. The value of the variable is set in the code-behind. i added a tag...
5
7799
by: David++ | last post by:
Hi folks, I would be interested to hear peoples views on whether or not 'pass by reference' is allowed when using a Web Service method. The thing that troubles me about pass-by-reference into...
18
3531
by: Ljordan2k6 | last post by:
Hi. First post here, so I apologize ahead of time if it isn't the best-formatted post. I am working on a form that has a listbox (named LstCustID) that is bound to an access table (named...
12
11003
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
7123
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,...
1
6842
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...
0
5430
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,...
1
4864
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...
0
4559
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...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
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 ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
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...

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.