I think I've just bumped into the limits of the Having Clause (Help file says 40 expressions, Mary says 99 and I know who I trust).
The question is, what happens if you overload the select... into... having clause? Does the whole thing fail? Is the clause truncated somehow?
It appears that the target table is being deleted, but then not re-created!
Here's what I got so far. Please pardon the long lines, I don't type 'em, I just paste from SQL view of the query designer! - ' Canberra Site Report export to Excel
-
If Sbf.SourceObject = "sfmSiteOnlyCanberra" Then
-
strExportTableName = "tblXLCanberraSites"
-
' Gather the selected Projects
-
For Each varSelect In Sbf.Controls("lstSite").ItemsSelected
-
strOr = strOr & "(tblSite.SiteNo) = '" & Sbf.Controls("lstSite").ItemData(varSelect) & "' Or "
-
Next varSelect
-
' lose the last ' OR '
-
strOr = Left(strOr, Len(strOr) - 4)
-
If strOr <> "" Then
-
strOr = "(" & strOr & ")"
-
End If ' strOr <> ""
-
-
strSQL = "SELECT tblSite.SiteNo, tblSite.SiteDescription, tblSite.NatMapRefN, tblSite.NatMapRefE, tblSite.MapNo, tblSite.GISZoneNo, qryAWName.NamCatch, qryAWName.NamSub, tbzElectorate.Electorate, tbzWaterType.WaterTypeDesc, tbzParam.DescShort, tblSample.SamNo, tblSample.Date " _
-
& "INTO " & strExportTableName & " " _
-
& "FROM tbzWaterType RIGHT JOIN (tbzParam RIGHT JOIN (((tblSite INNER JOIN qryAWName ON tblSite.AWCode = qryAWName.AWCode) INNER JOIN tbzElectorate ON tblSite.ElectID = tbzElectorate.ElectID) LEFT JOIN ((tblMonSite LEFT JOIN tblSample ON tblMonSite.GSPNo = tblSample.GSPNo) LEFT JOIN tblResult ON tblSample.SamNo = tblResult.SamNo) ON tblSite.SiteNo = tblMonSite.SiteNo) ON tbzParam.ParamNo = tblResult.ParamNo) ON tbzWaterType.WaterType = tblSite.WaterType " _
-
& "WHERE (((tblSite.SiteActive)=True)) " _
-
& "GROUP BY tblSite.SiteNo, tblSite.SiteDescription, tblSite.NatMapRefN, tblSite.NatMapRefE, tblSite.MapNo, tblSite.GISZoneNo, qryAWName.NamCatch, qryAWName.NamSub, tbzElectorate.Electorate, tbzWaterType.WaterTypeDesc, tbzParam.DescShort, tblSample.SamNo, tblSample.Date "
-
If strOr <> "" Then
-
strSQL = strSQL & " HAVING " & strOr
-
End If ' strOr <> ""
-
-
'Make note of any fields that have to have their data type fixed
-
ReDim arFixField(1, 0)
-
arFixField(0, 0) = "SamNo"
-
arFixField(1, 0) = "INTEGER"
-
iArrayCounter = 0
-
DoCmd.SetWarnings False
-
If Application.CurrentData.AllTables(strExportTableName).IsLoaded Then
-
DoCmd.Close acTable, strExportTableName, acSaveNo
-
End If ' Application.CurrentData.AllTables(strExportTableName).IsLoaded
-
DoCmd.RunSQL strSQL
-
For iLoop = 0 To iArrayCounter ' fix up any column datatypes as noted earlier
-
strExecuteCommand = "Alter Table " & strExportTableName & " ALTER COLUMN " & arFixField(0, iLoop) & " " & arFixField(1, iLoop)
-
DoCmd.RunSQL strExecuteCommand
-
Next iLoop
-
Depending on the user's back end tables and the choices they make from the multi-select listbox, this can end up with a len(strSQL) of > 11,000!, but that's within the 32,768 limit.
Oddly, when no table is created, the second RunSQL action (to fix up datatypes) doesn't cause an error.
Jim
5 2399
Stop Press!
I just noticed that when the operator makes no choice from the listbox, (making strOR = "" and therefore there is no Having clause at all), the same thing happens! The table is deleted but not re-created and the second RunSQL doesn't cause an error. (I rem'd out the SetWarnings False first).
If I paste strSQL into the SQL view of the query designer it works fine with a small Having clause or without one.
Things that make you go "Hmmm"
Jim
Stop Press!
If I paste strSQL into the SQL view of the query designer it works fine with a small Having clause or without one.
Jim
Actually, that turns out not to be the case. If I paste strSQL into the SQL view of the query designer, I can view the query in Datasheet view, but if I run the query I get
"You tried to assign the Null value to a variable that is not a Variant
data type"
Still hunting!
Jim
Actually, that turns out not to be the case. If I paste strSQL into the SQL view of the query designer, I can view the query in Datasheet view, but if I run the query I get
"You tried to assign the Null value to a variable that is not a Variant
data type"
Still hunting!
Jim
Got it!
It was the null value that put me onto it. One (and darn it, only one) of the Dates in tblSample were Null and that threw the whole thing out.
Big thanks to me for all my help! (No, not being snippy, I'm actually glad I sorted it myself)
Have a great weekend all.
Jim
We just love listening to your accent, mate! You understand, of course, that being "Down Under," everything you do in Access works bass ackwards!
Linq ;0)>
We just love listening to your accent, mate! You understand, of course, that being "Down Under," everything you do in Access works bass ackwards!
Linq ;0)>
Crikey! That explains a lot.
Jim (.^.) that's me smiling down-side-up!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Newbie |
last post by:
Dear friends,
I am having a hard time understanding how to use a SELECT CASE in ASP. I
have used it in VB but never in ASP scripting.
Scenerio:
I have 2 textboxes on a form that I have to...
|
by: Ian T |
last post by:
Hi,
I've got what I think (probably incorrectly) should be a simple SELECT :
Two colums with data like
col1 col2
1 50
1 51
2 50
|
by: malcolm |
last post by:
Example, suppose you have these 2 tables
(NOTE: My example is totally different, but I'm simply trying to setup
the a simpler version, so excuse the bad design; not the point here)
CarsSold {...
|
by: Adam Balgach |
last post by:
I am having a bit of a problem, and it might have to do with my
understanding of how select works...
basically what i am trying to simulate is a system:
client->gateway->server model. The...
|
by: jimh |
last post by:
I'm not a SQL expert. I want to be able to write a stored procedure
that will return 'people who bought this product also bought this...'.
I have a user table that links to a transaction table...
|
by: GreatAlterEgo |
last post by:
Hi,
This is my query which is embedded in a COBOL program.
EXEC SQL
SELECT DATE, AGE, DURATION, AMT
INTO :LDATE, :L.AGE, :L.DURATION, :L.AMT
FROM TAB1
WHERE CODE = :KEY.CODE
AND...
|
by: MP |
last post by:
vb6,ado,mdb,win2k
i pass the sql string to the .Execute method on the open connection to
Table_Name(const) db table
fwiw
(the connection opened via class wrapper:)
msConnString = "Data Source="...
|
by: pekx |
last post by:
Hi,
I create a script to pick up those records with duplication of IMIPROPSERVNO field, see below test1.sql, which is working....
test1.sql
1.SELECT IMIPROPSERVNO, COUNT(*)
2.FROM...
|
by: The.Daryl.Lu |
last post by:
Hi, two parts to my problem if someone can help address either one or
both:
1. I want to SELECT everything in the table if it matches the
criteria when the query button is pressed (this is just...
|
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: 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,...
|
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |