473,385 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Access:To chk the parameters of query and then run it

atksamy
91
Hi,

I am not sure how clear i can be in my question.
I have a table full of queries which i am running agaianst another table full of records.

consider i have a query in table like select * from table where

f < (a+b)/d

here suppose value of d is 0 then an error will occur i want to modify it such that if d = 0 then control must move on to next method.
is there any way other than error trapping. i mean by modifying the query

thanks
Nov 26 '08 #1
10 1622
rsmccli
52
Kinda fuzzy on some details there. If 'd' is a field from a query, then you could just filter those that =0 with a WHERE clause.

'I'm running a bunch of queries' or whatnot is hard to decipher. Are you running these queries from code or how is this all working? It is probably possible to do some sort of If...Then...Else or Select Case statement in the code to skip invalid records if using a WHERE clause is not viable.
Nov 26 '08 #2
atksamy
91
well d is a field from a table.

the code has the following statement

select * from table where


the remainig part of the statement are in a table which is executed in the form of a loop.
one of the condition in the table is f<(a+b)/d

which is returning erro because d might return 0 in some records
i cant change code as ther are other conditions which might get affected and then code will not be generic, as d may not be a part of all tables

i want to make change in this condition f<(a+b)/d
Nov 26 '08 #3
rsmccli
52
@atksamy
Dunno. I guess I suggest that you base your loop query to select from a query that has already filtered out any records where d = 0.

So more like:

SELECT * FROM (SELECT * FROM table WHERE d <> 0) AS Temp WHERE



or something of that nature.

Good luck to you.
Nov 26 '08 #4
atksamy
91
Hi,

This question is a better explanation for the thread " To chk the parameters of the query and run it"

I am using the following code to run a table of queries against a few tables of records.
I have a table query criteria which has a few conditions and i am trying to get each query to run against the tables.

The code works fine till it comes to a condition like f<((a+b)/d)
as here certain records may return 0 fro d and hence error occurs. Can anyone show me a way to get through this

Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Sub plausibilitaet_check()
  4.  
  5. Dim rs As DAO.Recordset
  6. Dim rs2 As ADODB.Recordset
  7. Dim db As database
  8. Dim strsql As String
  9. Dim tdf As TableDef
  10.  
  11. Set db = opendatabase("C:\Codebook.mdb")
  12. Set rs = db.OpenRecordset("Query criteria")
  13.  
  14. Set rs2 = CreateObject("ADODB.Recordset")
  15. rs2.ActiveConnection = CurrentProject.Connection
  16.  
  17. For Each tdf In CurrentDb.TableDefs
  18.  
  19.    If Left(tdf.Name, 4) <> "MSys" Then
  20.         rs.MoveFirst
  21.         strsql = "SELECT * From [" & tdf.Name & "] WHERE "
  22.  
  23.         Do While Not rs.EOF
  24.             On Error Resume Next
  25.  
  26.             rs2.Open strsql & " " & rs![query]
  27.  
  28.             If Err.Number = 0 Then
  29.                 On Error GoTo 0
  30.                 Do While Not rs2.EOF
  31.                 If Not rs2.EOF Then                            
  32.     msgbox "error"                            
  33.  
  34.                 End If
  35.  
  36.             rs2.MoveNext
  37.             Loop
  38.             End If
  39.             Err.Clear
  40.             rs2.Close
  41.             rs.MoveNext
  42.  
  43.         Loop
  44.     End If
  45. Next
  46.  
  47. End Sub
Nov 28 '08 #5
ChipR
1,287 Expert 1GB
I'm wondering if you could change that query to d<>0 AND f<((a+b)/d)
but I couldn't find anything about whether SQL would try to evaluate both of these if the first failed, so it may or may not work.
Nov 28 '08 #6
atksamy
91
i already tried that, i guess its evaluating both as it still throws up an error
Nov 28 '08 #7
ChipR
1,287 Expert 1GB
Ok, what if your condition is d<>0, f<((a+b)/d
Then you search your condition for a comma, and if there is one you construct a
SELECT * FROM (SELECT * FROM tdf.Name WHERE d<>0) WHERE f<((a+d)/d)
otherwise you just construct the string without the subquery.
Nov 28 '08 #8
missinglinq
3,532 Expert 2GB
atksamy, your duplicate posting of this question/problem has been merged with the current one! Please refrain from this prohibited behavior in the future.

From FAQs

Do Not Double Post Your Questions

Double posting is where you start a thread on a topic and then for some reason start another thread on exactly the same topic in the same forum. Please do not do this because

1. It makes it very hard for people to answer you especially if there are answers happening in all the threads you have started because they have to read 2 or more threads in order to see what has already been said.

2. It swamps the forum with your problem resulting in less attention for the other threads.

If you feel for some reason that you post has been overlooked (for instance it hasn't had any replies) please do not repost the question. Post a message to the thread you started, this will bump it back to the top of the thread list for the forum.

In point of fact, rsmccli gave you the same answer two days ago as Chip gave you today!

Thank you for your attention in this matter.


Linq ;0)>

Moderator

Nov 28 '08 #9
atksamy
91
Sorry about that I ll take care of that next time
Nov 28 '08 #10
atksamy
91
I have found a solution, just in case if anyone else is interested

f<IIf(d=0, 0, ((a+b)/d))
Dec 1 '08 #11

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

Similar topics

0
by: Chris McKenzie via .NET 247 | last post by:
I am trying to write an Ad Rotator component on my ASP.NET site,but keep running into an "interesting" problem. The routinestarts out by submitting the new ad information to the database(this part...
0
by: Wouter | last post by:
Hi, I am working on some transformations of XML data using Xslt sheets. One part in this process uses the XsltArguments class to pass on additional parameters to the xslt. My question is the...
2
by: roz | last post by:
Hello, I'm fairly new to VB programming and I've been going round the bend with this problem, so any nudges or shoves in the right direction would be greatly appreciated. I have a template...
2
by: k-man | last post by:
Hi: I have an MS Access query for a table called MyTable. One of my fields in the query is a custom field that looks like "MyField: = MyFunction(ID)" where ID is a field in MyTable. I have...
4
by: torontolancer | last post by:
Hi there how r u .I would really appriciate ur concern regarding checking out this code. its beind a command button and i am have a combo box selecing a query criteria and then pressing the button...
1
by: shovan mohanty | last post by:
Hi , Can anybody convert below access query into equivalent stored procedure. Also please advice in the below query,user defined function of VBA i.e anneeSelection41510() has been used in the...
4
by: Cirene | last post by:
I know that there are several ways to access/query data. (Stored procs, direct SQL statements, etc...) Typically I write a simple Stored Procedure, then access it from my webform like this... ...
14
by: iheartvba | last post by:
Hi I am running the following query in access query builder. The name of the query is "qryTempRecEFTBankedMaxDate": SELECT Max(qryTempRecEFTBanked.Dt) AS MaxOfDt FROM qryTempRecEFTBanked; it...
15
by: OzNet | last post by:
I have a query (with calculated fields) in Access (2007) and the data changes depending on the dates and staff person selected. I need to produce a series of graphs based on the data in this query...
1
by: AccessBeetle | last post by:
SELECT DISTINCT .Contact1Index, Contacts., Contacts., Contacts., Contacts., Contacts.prefix, Contacts.Suffix, Contacts., Contacts., Contacts.city, Contacts.state, Contacts.zip, ., tblStatusCloseout.,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.