473,493 Members | 4,147 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sub Passing Variables to Query

Just gearing up to do a complex series of update queries on a terrible
set of data.

I need this to work:

----------
Public Sub blah()

Dim Result As String
Result = 9
DoCmd.OpenQuery "NewQuery"

End Sub
-----------

Where the query criteria is [Result].

Currently the query asks me for 'Result' in a Parameter pop up, so my
parameter is not being passed. I also tried [Module1]![Result] and
[blah]![Result]. Still not working.

Thanks,

Christian

Feb 22 '07 #1
6 3604
On Feb 22, 12:48 pm, christianlo...@yahoo.com wrote:
Just gearing up to do a complex series of update queries on a terrible
set of data.

I need this to work:

----------
Public Sub blah()

Dim Result As String
Result = 9
DoCmd.OpenQuery "NewQuery"

End Sub
-----------

Where the query criteria is [Result].

Currently the query asks me for 'Result' in a Parameter pop up, so my
parameter is not being passed. I also tried [Module1]![Result] and
[blah]![Result]. Still not working.

Thanks,

Christian

Easiest is to modify the sub to run the query directly instead of
opening one.

Public Sub blah()
On Error Goto Stoprun
Dim db As Database
Dim sqlStr As String

Set db=CurrentDB
sqlStr= "InsertQryHereIncludingCriteria_UserVariblesIfNece ssary"
db.Execute sqlStr,dbFailOnError

Exit_Here:
Set db = Nothing
Exit Sub

Stoprun:
_DoSomethingToHandleError
End Sub

Feb 22 '07 #2
On Feb 22, 12:48 pm, christianlo...@yahoo.com wrote:
Just gearing up to do a complex series of update queries on a terrible
set of data.

I need this to work:

----------
Public Sub blah()

Dim Result As String
Result = 9
DoCmd.OpenQuery "NewQuery"

End Sub
-----------

Where the query criteria is [Result].

Currently the query asks me for 'Result' in a Parameter pop up, so my
parameter is not being passed. I also tried [Module1]![Result] and
[blah]![Result]. Still not working.

Thanks,

Christian

You'll want to use a querydef object, e.g.

Dim qdf As QueryDef

Set qdf = CurrentDb.QueryDefs("NewQuery")
qdf.Parameters("Result") = 9
qdf.Execute

Hope this helps,
Bruce
Feb 22 '07 #3
Thanks storrboy and Bruce for your help.

Now how do I pass a parameter with embedded quotes?

--
SubmidType = "(Not Like "CL" & "*" And Not Like "EP" & "*" And Not
Like "FQ" & "*" And Not Like "*" & "AR" & "*")"
--

Or just:

Not Like "CL" & "*" And Not Like "EP" & "*" And Not Like "FQ" & "*"
And Not Like "*" & "AR" & "*"

---------

I know I should just make this a subquery but it will need to change
as the program iterates. I didn't want to make a bunch of named
queries.

Feb 22 '07 #4
On Feb 22, 2:22 pm, christianlo...@yahoo.com wrote:
Thanks storrboy and Bruce for your help.

Now how do I pass a parameter with embedded quotes?

--
SubmidType = "(Not Like "CL" & "*" And Not Like "EP" & "*" And Not
Like "FQ" & "*" And Not Like "*" & "AR" & "*")"
--

Or just:

Not Like "CL" & "*" And Not Like "EP" & "*" And Not Like "FQ" & "*"
And Not Like "*" & "AR" & "*"

---------

I know I should just make this a subquery but it will need to change
as the program iterates. I didn't want to make a bunch of named
queries.
See the help file for "Using Quotes In Strings" o some such thing.
There are many examples and will depend on the method you chose to
use.
Feb 22 '07 #5
Unrelated question, what's wrong with this?

-------------
SepRank = Null

If Not IsNull(Entered) Then
j = InStr(1, Entered, "#")
If j <0 Then
SepRank = Mid(Entered, j + 1, 1)
End If
End If
--------------

It's supposed to separate out -

from - "asdasd #1"
to - "1"

(Please God, help these poor people in their completely screwed up
database!)

Thanks in advance.

Feb 22 '07 #6
On Feb 22, 2:19 pm, christianlo...@yahoo.com wrote:
-------------
SepRank = Null

If Not IsNull(Entered) Then
j = InStr(1, Entered, "#")
If j <0 Then
SepRank = Mid(Entered, j + 1, 1)
End If
End If
--------------
Answering my own questions..

When I took out 'SepRank=Null' it ran fine.

Feb 22 '07 #7

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

Similar topics

12
2940
by: zig | last post by:
I've posted this on alt.comp.lang.coldfusion, but is predominantly a javascript problem: I have a CF query which returns several rows of records. I wanted to have a checkbox on each record of...
0
1702
by: Omar K | last post by:
Hi, I am quite new to frontpage and SQL but I have a Stock Control access database / frontpage to set up. My last problem deals with the automatic updating of the total quantity of stock with parts...
7
8977
by: Scott | last post by:
I need help to modify the code below to pass url variables from a framset. The click to run this will be in the mainFrame. This script works well in a non-frame page. Grabs the current url...
4
1951
by: Doruk | last post by:
The problem that we are experiencing is simple: We want to pass certain parameters from a page with several server controls to another page. We want to do this in a dotnet compliant manner,...
2
2282
by: Keith | last post by:
Good Afternoon, New to .Net. I am trying to pass date/time values to a MS Access query depending on what value is selected from a dropdown list box (January, February, etc). I have declared...
9
3273
by: laurenq uantrell | last post by:
I've gotten sort of fed up with dealing with regional date settings on the client side and am considering the following scheme - just wondering if anyone has a negative view of it or not: ...
7
1869
by: Smokey Grindle | last post by:
For a website that has users logged into it using sessions, its it best to pass data between pages in session variables or through query strings?
3
1765
by: absoft | last post by:
What are the best practices for passing UserId and Password stored in the Session state on the UI layer e.g. ASP.NET Web Forms to the Business Layer or the Data Layer.
7
8176
by: The Doctor | last post by:
A rather elementary question, In VB5, how can I pass a variable from one form to another?
6
2617
by: jej1216 | last post by:
I am trying to put together a PHP search page in which the user can select none, one, two, or three fields to search, and then the results php will build the SQL with dynamic where caluses to reflect...
0
7119
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,...
0
6989
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...
0
7157
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,...
0
5453
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,...
0
3088
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1400
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
644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
285
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.