473,378 Members | 1,391 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,378 software developers and data experts.

Long Query in VBA

77
Guys, I keep landing into problems (Good for me as I'm learing a lot from this) and here is another one for the brainy ones:

I have the following query that I need to execute in Access VBA

Expand|Select|Wrap|Line Numbers
  1. SELECT  HCRecon.*,EMP_MASTER.EMP_ID as WFM_EMPID, EMP_MASTER.EMP_NAME as WFM_EMPNAME,EMP_MASTER.TL_ID as WFM_SUPID, EMP_MASTER.TL_NAME as WFM_SUPNAME,emp_master.designation as WFM_DESIG,emp_master.function as WFM_FUNCTION,iif(((emp_master.function='Production' or emp_master.function='Nesting') and emp_master.status='Active'),'On Floor',emp_master.status) as WFM_STATUS,iif(((emp_master.function='Production' or emp_master.function='Nesting') and emp_master.status='Active'),'Billable','Non-Billable') as WFM_BILLNONBILL,emp_master.voice_nonvoice as WFM_VNV,'Tube' as WFM_PROCESS
  2. FROM EMP_MASTER INNER JOIN HCRecon ON  EMP_MASTER.EMP_ID=HCRecon.EMP_ID where hcrecon.function='Production'
  3. UNION ALL
  4. SELECT  HCRecon.*,EMP_MASTER.EMP_ID as WFM_EMPID, EMP_MASTER.EMP_NAME as WFM_EMPNAME,EMP_MASTER.TL_ID as WFM_SUPID, EMP_MASTER.TL_NAME as WFM_SUPNAME,emp_master.designation as WFM_DESIG,emp_master.function as WFM_FUNCTION,iif(((emp_master.function='Production' or emp_master.function='Nesting') and emp_master.status='Active'),'On Floor',emp_master.status) as WFM_STATUS,iif(((emp_master.function='Production' or emp_master.function='Nesting') and emp_master.status='Active'),'Billable','Non-Billable') as WFM_BILLNONBILL,emp_master.voice_nonvoice as WFM_VNV,'Tube' as WFM_PROCESS
  5. FROM EMP_MASTER LEFT JOIN HCRecon ON  EMP_MASTER.EMP_ID=HCRecon.EMP_ID WHERE HCRecon.EMP_NAME is null and (emp_master.function='Production' or emp_master.function='Nesting' or emp_master.function='Training')
  6. UNION ALL
  7. SELECT  HCRecon.*,EMP_MASTER.EMP_ID as WFM_EMPID, EMP_MASTER.EMP_NAME as WFM_EMPNAME,EMP_MASTER.TL_ID as WFM_SUPID, EMP_MASTER.TL_NAME as WFM_SUPNAME,emp_master.designation as WFM_DESIG,emp_master.function as WFM_FUNCTION,iif(((emp_master.function='Production' or emp_master.function='Nesting') and emp_master.status='Active'),'On Floor',emp_master.status) as WFM_STATUS,iif(((emp_master.function='Production' or emp_master.function='Nesting') and emp_master.status='Active'),'Billable','Non-Billable') as WFM_BILLNONBILL,emp_master.voice_nonvoice as WFM_VNV,'Tube' as WFM_PROCESS
  8. FROM EMP_MASTER RIGHT JOIN HCRecon ON  EMP_MASTER.EMP_ID=HCRecon.EMP_ID WHERE EMP_MASTER.EMP_NAME is null and hcrecon.function='Production';
  9.  
Apparantly, this is too long a query to be stored in any variable?

Even when i divide this query into three parts and store it in three different String or Variant variables namely vSQL1, vSQL3 & vSQL3 and then use the following statement:

Expand|Select|Wrap|Line Numbers
  1. Msgbox vSQL1 & vSQL2 & vSQL3
  2.  
I don't get the complete sql statement in the message box. Individual message box statement does give me individual parts as a whole...

Need to join it somehow and execute... Any inputs please?
Sep 4 '08 #1
9 2975
FishVal
2,653 Expert 2GB
String Data Type


There are two kinds of strings: variable-length and fixed-length strings.

A variable-length string can contain up to approximately 2 billion (2^31) characters.


A fixed-length string can contain 1 to approximately 64K (2^16) characters.
Note A Public fixed-length string can't be used in a class module.

The codes for String characters range from 0–255. The first 128 characters (0–127) of the character set correspond to the letters and symbols on a standard U.S. keyboard. These first 128 characters are the same as those defined by the ASCII character set. The second 128 characters (128–255) represent special characters, such as letters in international alphabets, accents, currency symbols, and fractions. The type-declaration character for String is the dollar sign ($).
well enough. ;)

Kind regards,
Fish
Sep 4 '08 #2
yaaara
77
Hi Fish,

The variables I'm using are indeed declared using the "$" symbol..

I have also tried declaring them using the following syntaxes:

Expand|Select|Wrap|Line Numbers
  1. Dim vSQL$
  2. Dim vSQL1 as String
  3. Dim vSQL2 as Variant
  4.  
Still these variables are not storing the complete query string... Any clues please?
Sep 4 '08 #3
NeoPa
32,556 Expert Mod 16PB
I suggest you add the line :
Expand|Select|Wrap|Line Numbers
  1. Debug.Print StrLen(strSQL)
to the end of your code, then post the code, and the result of the added line for us to look at the details of what may be going wrong.

If your variable name is other than strSQL then substitute your name in its place obviously.
Sep 5 '08 #4
yaaara
77
Hi,

When I add this line, it gives me an error message "Compile error: Sub or function not defined"

The highlight is on "strlen"

Any clues about what I may be doing wrong?
Sep 5 '08 #5
NeoPa
32,556 Expert Mod 16PB
Only in trying to follow my instructions :( I was confused between different languages. I meant :
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Len(strSQL)
It's been nearly two decades since I last coded in c. How bizarre is that.
Sep 5 '08 #6
yaaara
77
Lol.. I was wondering the same and found out that the len command gives the correct length as it is supposed to be.. but still when i put it in a messagebox, it gets truncated?
Sep 5 '08 #7
NeoPa
32,556 Expert Mod 16PB
As I understand it, the displaying of it is not your main problem. At least now you know that the string manipulation is working fine.

To display your string simply use :
Expand|Select|Wrap|Line Numbers
  1. Debug.Print strSQL
From there you can copy/paste the results somewhere where you can study it in more detail.
Sep 5 '08 #8
yaaara
77
The Debug.Print statement gives the same output as in the Message Box... No luck :-(
Sep 5 '08 #9
NeoPa
32,556 Expert Mod 16PB
OK then, try :
Expand|Select|Wrap|Line Numbers
  1. For lng=1 To Len(strSQL) By 250:? Mid(strSQL,lng,250);:Next lng
Copy and paste it into the Immediate Pane (Ctrl-G) when the code is stopped and strSQL has been set up.

PS. Alternatively, replace the ? with Debug.Print and include it in the relevant part of your code of course.
Sep 5 '08 #10

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

Similar topics

4
by: Karaoke Prince | last post by:
Hi There, I have an update statement to update a field of a table (~15,000,000 records). It took me around 3 hours to finish 2 weeks ago. After that no one touched the server and no...
4
by: Gary | last post by:
I am having a problem executing long running queries from an ASP application which connects to SQL Server 2000. Basically, I have batches of queries that are run using ADO in a loop written in...
2
by: Justin Koivisto | last post by:
I am attempting to execute a *long* query string via a ADODB.Recordset.Open (queryStr) call. Most of the time, the query string will be less than 100 characters, but in some cases, it may be up to...
4
by: Kory | last post by:
How do you stop a long running query with a SQLConnection or SQLCommand? Calling Close on either just waits until the query is done. Is there a way to stop it? The following on a long query ...
4
by: justin tyme | last post by:
Hello Experts! I would like to combine (which may not be the correct technical term) two text fields from the same table in a query. Specifically, text field A and text field B are both lists of...
5
by: XML newbie: Urgent pls help! | last post by:
function to convert string to 1 dimensional array of long in VB.Net
1
by: Aaron West | last post by:
Try this script to see what queries are taking over a second. To get some real output, you need a long-running query. Here's one (estimated to take over an hour): PRINT GETDATE() select...
3
by: laurentc via AccessMonster.com | last post by:
Hi. I have an issue with my Access project. I have rather big tables of data (about 11 000 rows). These tables are historical product quotations, so they are very simple : - MyDate...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
3
by: Eric Davidson | last post by:
DB2 9.5 I keep geting the message. SQL0101N The statement is too long or too complex. SQLSTATE=54001 When one of my sql statements takes over 60 seconds to compile the sql statement. Is...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.