I have a query that I change the table in depending on the selection of the customer. I have done this before and it works fine except now I need to have a DMin statement and I keep getting an error on it.Heres the code - Set StageStsMM = db.QueryDefs("StageStsMM")
-
StageStsMM.SQL = "SELECT " & vst & ".SASS_number, Params.Number_stages, " & vst & ".Shoot_date AS shootdate, " & vst & ".ShooterNumber, " & vst & ".Class AS Class, Shooting_Class.Description, Shooting_Class.ScoringCheck, " & _
-
"" & vst & ".Time1 , " & vst & ".TTime1, " & vst & ".Misses1, " & vst & ".Penelties1, " & vst & ".Time2, " & vst & ".TTime2, " & vst & ".Misses2, " & vst & ".Penelties2, " & vst & ".Time3, " & vst & ".TTime3, " & _
-
"" & vst & ".Misses3, " & vst & ".Penelties3, " & vst & ".Time4, " & vst & ".TTime4, " & vst & ".Misses4, " & vst & ".Penelties4, " & vst & ".Time5, " & vst & ".TTime5, " & vst & ".Misses5, " & vst & ".Penelties5, " & _
-
"" & vst & ".Time6, " & vst & ".TTime6, " & vst & ".Misses6, " & vst & ".Penelties6, " & vst & ".Time7, " & vst & ".TTime7, " & vst & ".Misses7, " & vst & ".Penelties7, " & vst & ".Time8, " & vst & ".TTime8, " & _
-
"" & vst & ".Misses8, " & vst & ".Penelties8, " & vst & ".Time9, " & vst & ".TTime9, " & vst & ".Misses9, " & vst & ".Penelties9, " & vst & ".Time10, " & vst & ".TTime10, " & vst & ".Misses10, " & vst & ".Penelties10, " & _
-
"" & vst & ".Time11, " & vst & ".TTime11, " & vst & ".Misses11, " & vst & ".Penelties11, " & vst & ".Time12, " & vst & ".TTime12, " & vst & ".Misses12, " & vst & ".Penelties12, " & vst & ".Time13, " & vst & ".TTime13, " & vst & ".Misses13, " & vst & ".Penelties13, " & vst & ".Time14, " & _
-
"" & vst & ".TTime14, " & vst & ".Misses14, " & vst & ".Penelties14, " & vst & ".Time15, " & vst & ".TTime15, " & vst & ".Misses15, " & vst & ".Penelties15, " & vst & ".Time16, " & vst & ".TTime16, " & vst & ".Misses16, " & _
-
"" & vst & ".Penelties16, " & vst & ".Time17, " & vst & ".TTime17, " & vst & ".Misses17, " & vst & ".Penelties17, " & vst & ".Time18, " & vst & ".TTime18, " & vst & ".Misses18, " & vst & ".Penelties18, " & vst & ".TotalTime, " & _
-
"Params.Shoot_date, Params.Club_name, Params.RegionalName, Master.Alias, Params.MisseTime, Params.PenaltiesTime, DMin("[tTime1]","[" & vst & "]","[tTime1] > 0 and class = '" & [Class] & "'") AS mTime1, " & _
-
"DMin("[tTime2]","[" & vst & "]","[tTime2] > 0 and class = '" & [Class] & "'") AS mTime2, DMin("[tTime3]","[" & vst & "]","[tTime3] > 0 and class = '" & [Class] & "'") AS mTime3, DMin("[tTime4]","[" & vst & "]","[tTime4] > 0 and class = '" & [Class] & "'") AS mTime4, " & _
-
"DMin("[tTime5]","[" & vst & "]","[tTime5] > 0 and class = '" & [Class] & "'") AS mTime5, DMin("[tTime6]","[" & vst & "]","[tTime6] > 0 and class = '" & [Class] & "'") AS mTime6, DMin("[tTime7]","[" & vst & "]","[tTime7] > 0 and class = '" & [Class] & "'") AS mTime7, " & _
-
"DMin("[tTime8]","[" & vst & "]","[tTime8] > 0 and class = '" & [Class] & "'") AS mTime8, DMin("[tTime9]","[" & vst & "]","[tTime9] > 0 and class = '" & [Class] & "'") AS mTime9, DMin("[tTime10]","[" & vst & "]","[tTime10] > 0 and class = '" & [Class] & "'") AS mTime10, " & _
-
"DMin("[tTime11]","[" & vst & "]","[tTime11] > 0 and class = '" & [Class] & "'") AS mTime11, DMin("[tTime12]","[" & vst & "]","[tTime12] > 0 and class = '" & [Class] & "'") AS mTime12, DMin("[tTime13]", " & _
-
"[" & vst & "]","[tTime13] > 0 and class = '" & [Class] & "'") AS mTime13, DMin("[tTime14]","[" & vst & "]","[tTime14] > 0 and class = '" & [Class] & "'") AS mTime14, DMin("[tTime15]","[" & vst & "]","[tTime15] > 0 and class = '" & [Class] & "'") AS mTime15, " & _
-
"DMin("[tTime16]","[" & vst & "]","[tTime16] > 0 and class = '" & [Class] & "'") AS mTime16, DMin("[tTime17]","[" & vst & "]","[tTime17] > 0 and class = '" & [Class] & "'") AS mTime17, DMin("[tTime18]","[" & vst & "]","[tTime18] > 0 and class = '" & [Class] & "'") AS mTime18, " & _
-
"" & vst & ".MSafety1, " & vst & ".MSafety2, " & vst & ".MSafety3, " & vst & ".MSafety4, " & vst & ".MSafety5, " & vst & ".MSafety6, " & vst & ".MSafety7, " & vst & ".MSafety8, " & vst & ".MSafety9, " & vst & ".MSafety10, " & vst & ".MSafety11, " & vst & ".MSafety12, " & _
-
"" & vst & ".MSafety13, " & vst & ".MSafety14, " & vst & ".MSafety15, " & vst & ".MSafety16, " & vst & ".MSafety17, " & vst & ".MSafety18, " & vst & ".Shootorder1, " & vst & ".Shootorder2, " & vst & ".Shootorder3, " & _
-
"" & vst & ".Shootorder4, " & vst & ".Shootorder5, " & vst & ".Shootorder6, " & vst & ".Shootorder7, " & vst & ".Shootorder8, " & vst & ".Shootorder9, " & vst & ".Shootorder10, " & vst & ".Shootorder11, " & vst & ".Shootorder12, " & _
-
"" & vst & ".Shootorder13, " & vst & ".Shootorder14, " & vst & ".Shootorder15, " & vst & ".Shootorder16, " & vst & ".Shootorder17, " & vst & ".Shootorder18, " & vst & ".MatchDQ FROM Params, Master INNER JOIN (Shooting_Class INNER JOIN " & vst & " ON Shooting_Class.Class = " & vst & ".Class) ON Master.SASS_number = " & vst & ".SASS_number " & _
-
"WHERE (((Shooting_Class.ScoringCheck)=False) AND ((" & vst & ".MatchDQ)=False))"
the first Dmin statement gives an error "Expected end of statement"
I've copied the sql statement directly from the query only changing the table name to the " & Vst & " which is replaced with the correct selected table name.
I have never used the Dmin statement before in a query build in VBA so can someone tell me how that statement should be?
Thanks again for your help.
5 855
I think your table name is wrong in the DMin statements
It should be of the form -
DMin("[tTime2]", "vst", "Criteria")
-
where Criteria as whatever you want
If you type "DMin("[tTime2]", "vst", "Criteria")"
into the immediate window, you should see if this is giving the correct result.
Quite frankly, with a monster SQL statement like that, I tend to build it in the Query Builder and add additional statements until I have the complete SQL which I paste into my VBA
Phil
I'll give that a try and let you know.
Thanks
That didn't work either still get the same error. Any other suggestions.
NeoPa 32,556
Expert Mod 16PB
I'm surprised you still need to be told, at this stage after >400 posts, that posting VBA that creates SQL is less than bright.
Please read How to Debug SQL String first.
If you're still having problems then certainly feel free to share the SQL string that's failing.
As a further tip - Using Domain Aggregate functions within SQL is very rarely a recommended approach. That said, get your basics sorted out first before moving on to anything which would be classed as optimisation.
NeoPa 32,556
Expert Mod 16PB
Having looked at Phil's comment it seems clear you're using double-quotes (") within your intended SQL as well as in the VBA used to create that string. That's never going to work out for you. See Quotes (') and Double-Quotes (") - Where and When to use them.
@Tom.
I think of you as a very long-term member. Would I be right in thinking you've just recently moved towards SQL work after working in non-SQL based areas before now? If so, read the two linked threads as you should find them very helpful.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John Abel |
last post by:
I'm having a problem building pysqlite. I've downloaded the
sqlite_source.zip, and sqlitedll.zip and extracted them to a directory.
I've then extracted pysqlite-0.4.3. I've run the lib command,...
|
by: Eskil |
last post by:
Hi
I have a form that supplies my query with information on two different
variables. The form uses a lookup to display a list of 5 different
customer types and 5 different types of...
|
by: Mossy |
last post by:
I am currently moving a table from a msSQL DB to a MySQL DB.
I am trying to build the bones of an insert statement by adding strings
to a select statement.
SELECT '(' + job_referenceno + ',...
|
by: grabit |
last post by:
Hi Mary
this is the problem child (query)
<!---Query db for page info--->
<cfquery name="showtopics" datasource="parrots">
SELECT categories.catID, threads.threadID, threads.posttype,...
|
by: ashutoshvyas |
last post by:
I want to write such criteria in the query of microsoft ACCESS, which can give records with secondlast date?
table & fields............desired output
no-name-date..............name-date...
|
by: manoj9849967222 |
last post by:
Hi All
I have a problem with query.
I have designed a simple query which sould give me itemwise total qty sales during a given period.
the fields in the query are
startdate,...
|
by: viki1967 |
last post by:
Problem with query ASP and MySQL
Hi there.
I have this fields in the tbl (mysql) :
- ID (unique)
- user_name (text)
- Date (yyyy-mm-dd)
- Description (text - case A or B or C -)
|
by: cdhaynes |
last post by:
Hi, I am using unbound text boxes in the header of a form to allow the user to search on a number of fields. I am using VBA to build a query string based on these and it has been fine when comparing...
|
by: ajhayes |
last post by:
Hello everyone,
This is my first time posting here and I'm hoping someone can help me out. I'm a relative newbie to Access and am pretty much learning as I go along, so please bear with me.
...
|
by: kadishzm |
last post by:
Hi Everyone, I have recently been tasked with taking over a bunch of Access databases that I didn't create. My VBA skills are weak to say the best but I have a particular problem I am working on....
|
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$) {
}
...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: 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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |