Suggestion about dealing with subqueries that need string analysis - sql

I need to create a query on the fly through VBA that get some strings from a table based on a set of criteria selected by the user . From the results of that first query I need to find the position of certain characters in the strings and only select the one that have the characters at a given position. This need to be done quickly as it then needs to be displayed in a combo box for the user to select before he runs a full other query.
So my question is what is the fastest/best way to do this ?
Should I put the result of the first query in a temporary table , analyze the strings from that table, delete the records that don't meet the selection and then run a query to display in the combo box from that table ?
Thank you

Related

how to get query criteria in access vba

Now I am trying to create customize query design view form with Access VBA. I want to show fields name and criteria of saved query.
For example, SQL statement that executed by QueryDef.sql is
SELECT AllCars.ID, AllCars.CarName
FROM AllCars
WHERE (((AllCars.ID) Between 15 And 25) AND ((AllCars.MinPay)<1000)) ;
I would like to get criteria expressions( ID = Between 15 And 25, MinPay = <1000) and field names(ID , CarName) from it.
I can get field name but I am not sure how to get query criteria expression in Access VBA.
I tried to split sql statement but I think this is not a best way for multiple criteria expressions.
If getting criteria in access vba may be possible, could someone help me?
Thanks in advance.
Change the code that creates the saved query: instead of saving all the SQL together, save the field names separately and the expressions separately.
To keep all the fields together but in a way that you can later separate them, put the character ";" between the field names, and to separate them you will use the split function.
You can do the same for the expressions, and when you read the saved data you associate the position in the array of the expression with the position of the field in the array and thus you connect them together to show the user which expression applies to which field.
In the same way you build the query

Searching for string data in multiple rows

Good morning,
I put together a statement that works with single string searching. I wanted to know if its possible to retrieve multiple string data from different rows in a single search. I created the statement on sql management studio, I then modified it so in our program it prompts the user to enter the order number they are looking for in the row.
SELECT HID, INumber, SlsrdrNmbr, ShpNm, CustomerNumber, InvoiceDate, BlncD,Comments
FROM dbo._adhoc_Inv
WHERE BillNumber = '512315'
AND Comments LIKE '%{{enter D}}%'
prompt pops up
user enters number D-12313
Ideally I would like for them to enter multiple numbers, because they need to match the D numbers with our internal set of the numbers we have in our system.
So this works just fine, brings up the data I want. I want to make it easier by showing multiple search results so they don't need to close the window and search again. Is is possible to do what I am looking for? I am still a bit of a novice.
I would like to add if I add multiple D numbers that are on the SAME row, results will show since its the same row being retrieved.
Thank you

create new query based on access form

Here is my problem.
I am working with a database that is VERY simple, it has one table with 21 fields and a series of values. I have created a simple select query that selects 2 fields and generates a total value based on a query calculations field.
What I would like to do is to have an input form with combo boxes that allows users to pass in which fields they would like to select. Basically creating a GUI for someone LESS skilled (if that's possible) than myself to run the query.
Currently I have 21 potential fields. Would I have to create 21 x 21 queries and then try to write some kind of code that would link to the appropriate query if the criteria were selected from the combo boxes? Is there some kind of VBA script that could generate the query on the fly repeatedly?
Any hints on the way forward would be very helpful I've never used VBA but willing to thrash around if someone points in the right direction.
As per Comments, below = SQL for query
SELECT paddling.Paddling, boating.Boating, [boating]![Boating]*[paddling]![Paddling] AS Expr1
FROM paddling INNER JOIN boating ON paddling.useSpace = boating.useSpace;

Calculating the Sum of values in ms-access

I have created a query to calculate the sum of all of the profit values in a table, I tried to output this to a textbox on the main form of my database and I just the error #NAME?.
Has anyone tried this before and are there any major things I am missing?
We would need to see some code/design details to understand why your text box gets that #Name error.
Without those details, I'll just suggest you consider a DSum() expression, instead of a query, to load the text box. And DSum() is kind of like a SELECT query, but returns only a single value instead of a result set.
DSum("YourNumericField", "YourTable")
Examine the DSum online help topic for more details. You might find the optional Criteria parameter useful (like a WHERE clause in a SELECT statement) if you ever want to sum only a subset of rows from your table.
DSum("YourNumericField", "YourTable", "account_status = 'ACTIVE'")
If you have create query to calculate the sum called "querySum". On the form property sheet, make sure selection type you change to FORM, go to Data and select "querySum" as record source.
And then, click text box, go to the property sheet and choice Data > Control Source. So you can choice column from query to the text box.
Otherwise, if you want to use VBA. You can do like this
DSum("NumericField", "YourTable")
Or with condition
DSum("NumericField", "YourTable", "type = 'Payment'")

ms-access listbox weirdness (memory issue?)

i have a huge sql query that is attached to the rowsource of a listbox.
the SQL statement seen here:
ms-access: select from another query
actually returns the correct information if that information is under 2 records.
however if it returns more than 2 records it still populates the listbox but it populates it with null values. when i right click on one of the values and press COPY, it gives me this message:
"there isnt enough memory to retrieve data for the list box"
But does the query work if it is run separately? And is the number of columns in the query the same number of columns as you've specified in the listbox Column Count property?
In your reply you state that you have to combine it? Why? Basic trouble shooting is to see if you can run the query separate from the lixtbox.