[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

A REAL TOUGH QUERY!!

Posted on 1998-08-25
6
Medium Priority
?
181 Views
Last Modified: 2010-04-30
I am working with an access database. I am setting up a query form, where users can set their criteria in text boxes which are labelled.  Now, I understand that I must evaluate
each and every textbox to see if it is valid and run a query on my access table.

Right now I am doing this:

  Dim f_voltacmin As Integer
    If voltacmin.Text = "" Then
      ' do nothing
    Else
        f_voltacmin = voltacmin.Text
        Set temprst = dse.Database.OpenRecordset("SELECT *" _
        & " FROM MASTER" _
        & " WHERE VOLTAGE_AC >=  " & f_voltacmin & " OR VOLTAGE_AC_MIN >=  " & f_voltacmin & " ")
   
End If

Set dse.Recordset = temprst

and then I am running this again and again with different fields, I will modularize it later...

But I have realized that it opens up the table each and every time, and the previous SQL statement gets lost. Even though I have set the database recordset to the temp recordset.  But I think when I fill in the SELECT and FROM, that is what screws it up.  What I want to do is use the WHERE clause without the FROM, because I don't want to select the same table each time, I want to select my query up to date.

How can I execute multiple SQL expressions like above for the same table at different times? I need to execute them multiple times because I need to evaluate the user input, to see if I can do it or not.

What I essentially want to do is query my table, and query that query, query that subquery and so on until I am done.

How do I DO THIS!!!!

Thanks in advance...
0
Comment
Question by:qurashi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1430993
Option Explicit

Private Sub Command1_Click()
Dim f_voltacmin 'As Integer not for here
        If voltacmin.Text = "" Then
            MsgBox " Nothing"
          ' do nothing
        Else
            f_voltacmin = voltacmin.Text
            MsgBox f_voltacmin
        End If

End Sub

0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1430994
Hi, You can explicit the  f_voltacmin as string
 and  voltacmin.Text  as string as well.

 but You cannot place a string variable into Integer...
 NOT GOOD: >> Dim f_voltacmin As Integer
                         If voltacmin.Text = "" Then
                         ;.....
                         f_voltacmin = voltacmin.Text   <<< This is wrong
0
 

Author Comment

by:qurashi
ID: 1430995
That is not the answer I am looking for! I guess I was vague.
I don't really care about the data types and such, what I am concerned about is how to perform an SQL subquery on an existing table, and then perform another SQL subquery on that query, and another SQL subquery on that subquery and so on in regards to what I am doing with getting user input.

So essentially I want to filter out records based on one criteria, and then on that list, perform another filter to get it smaller and so on and on... for the rest of the criteria.  It may seem inefficient, but that is the way it has to be done!!!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:JayMerritt
ID: 1430996
Each field in your SELECT can be a SELECT.

Something like this:

SELECT (Select Volts from tblVolts1 Where Volts = 123) As Field1, (Select Volts from tblVolts2 Where Volts = 456) As Field2
 
0
 
LVL 1

Expert Comment

by:lawnranger
ID: 1430997
Seems too easy...what's the catch?

Use the Filter method as in;
' create recordset from first WHERE criteria
  temprs=MainDB.OpenRecordset("SELECT whatever
         FROM Table WHERE Voltage=Something",dbOpenDynaset)
'then loop on subsequent criteria
  temprs.Filter="Voltage=SomethingElse"
  Set temprs=temprs.OpenRecordset()

0
 
LVL 1

Accepted Solution

by:
lawnranger earned 400 total points
ID: 1430998

Use the Filter method as in;
' create recordset from first WHERE criteria
   temprs=MainDB.OpenRecordset("SELECT whatever
          FROM Table WHERE Voltage=Something",dbOpenDynaset)
'then loop on subsequent criteria
   temprs.Filter="Voltage=SomethingElse"
   Set temprs=temprs.OpenRecordset()
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question