473,804 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL does not work in VBA, but does with tweaking in QBE

I have an application that uses SQL. I am writing a new piece to it, so I
used the same approach that worked before. I set up a string and add to it,
i.e. strMySql = "some Sql Statement" and then strMySql = strMySql + "some
other new statement".

The program keeps crashing saying I am running an invalid operation. I go
to debug.print and copy the contents of the strMySql to the sql window.
Sure enough, where the sql statement wrapped in the Immdiates window, the
statement got split to a new line in the SQL window. I take out the space
at the end of the line and the next line snaps back into place to form a
coninuous statement once again. At this point, I can change back to the QBE
window and the statement is set up properly and will execute. But in VBA it
will not and I think that part that wraps in the Immdediate window has
nothing to do with my code.

Can anyone venture a guess as to what I am doing wrong?
Thanks
Nov 12 '05 #1
5 1729
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Are you putting spaces in the SQL statements in your VBA strings.
IOW:

strMySQL = "Select * From myTable"
strMySQL = strMySQL & "Where X = Y"

This will concatenate to

Select * From myTableWhere X = Y
^^

See the error where I didn't put a space after the myTable in the
first strMySQL assignment. This will cause an SQL syntax error when
the SQL command is attempted.

Therefore, put extra spaces at the end of your strings to ensure the
concatenation properly separates all elements of the SQL statement.

MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQAo6Q4echKq OuFEgEQJ1QACg4h Egrk5utCbp/dcRlJANjyNRUxkA n0iI
ofVMmEVfaiVXyyh VbcwK4fG+
=2310
-----END PGP SIGNATURE-----
Colleyville Alan wrote:
I have an application that uses SQL. I am writing a new piece to it, so I
used the same approach that worked before. I set up a string and add to it,
i.e. strMySql = "some Sql Statement" and then strMySql = strMySql + "some
other new statement".

The program keeps crashing saying I am running an invalid operation. I go
to debug.print and copy the contents of the strMySql to the sql window.
Sure enough, where the sql statement wrapped in the Immdiates window, the
statement got split to a new line in the SQL window. I take out the space
at the end of the line and the next line snaps back into place to form a
coninuous statement once again. At this point, I can change back to the QBE
window and the statement is set up properly and will execute. But in VBA it
will not and I think that part that wraps in the Immdediate window has
nothing to do with my code.

Can anyone venture a guess as to what I am doing wrong?
Thanks


Nov 12 '05 #2

"MGFoster" <me@privacy.com > wrote in message
news:aT******** **********@news read1.news.pas. earthlink.net.. .
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Are you putting spaces in the SQL statements in your VBA strings.
IOW:

strMySQL = "Select * From myTable"
strMySQL = strMySQL & "Where X = Y"

This will concatenate to

Select * From myTableWhere X = Y
^^

See the error where I didn't put a space after the myTable in the
first strMySQL assignment. This will cause an SQL syntax error when
the SQL command is attempted.

Therefore, put extra spaces at the end of your strings to ensure the
concatenation properly separates all elements of the SQL statement.

MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQAo6Q4echKq OuFEgEQJ1QACg4h Egrk5utCbp/dcRlJANjyNRUxkA n0iI
ofVMmEVfaiVXyyh VbcwK4fG+
=2310
-----END PGP SIGNATURE-----
\
Yes, I'm putting in the spaces. There were a couple of errors where I had
not put in the spaces, but I got those fixed before I posted this. The
thing is, the SQL statement breaks into two lines when I copy the string
from the Immediates window to the SQL window. When I eliminate that break,
I can run the SQL from that window. I have checked the length of the
statement and now think that this could be the problem. The length of the
line that gets split is 1299 characters and it gets split into two lines of
1023 characters on one line and the 276 characters on the next line; it
seems that I have reached the end of the capacity of a string. What do I do
now? Can I use two variables to split the SQL Statement in two and then
concatenate them? How might the coding for that look?

Thanks

Colleyville Alan wrote:
I have an application that uses SQL. I am writing a new piece to it, so I used the same approach that worked before. I set up a string and add to it, i.e. strMySql = "some Sql Statement" and then strMySql = strMySql + "some other new statement".

The program keeps crashing saying I am running an invalid operation. I go to debug.print and copy the contents of the strMySql to the sql window.
Sure enough, where the sql statement wrapped in the Immdiates window, the statement got split to a new line in the SQL window. I take out the space at the end of the line and the next line snaps back into place to form a
coninuous statement once again. At this point, I can change back to the QBE window and the statement is set up properly and will execute. But in VBA it will not and I think that part that wraps in the Immdediate window has
nothing to do with my code.

Can anyone venture a guess as to what I am doing wrong?
Thanks

Nov 12 '05 #3
The length of your string should only be an issue if you are trying to apply
it to a form or report recordsource as I believe these have a lenght
limitation. More help could be provided if we could see the code section in
question.

Mike Storr
www.veraccess.com


Yes, I'm putting in the spaces. There were a couple of errors where I had
not put in the spaces, but I got those fixed before I posted this. The
thing is, the SQL statement breaks into two lines when I copy the string
from the Immediates window to the SQL window. When I eliminate that break, I can run the SQL from that window. I have checked the length of the
statement and now think that this could be the problem. The length of the
line that gets split is 1299 characters and it gets split into two lines of 1023 characters on one line and the 276 characters on the next line; it
seems that I have reached the end of the capacity of a string. What do I do now? Can I use two variables to split the SQL Statement in two and then
concatenate them? How might the coding for that look?

Thanks


Nov 12 '05 #4
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Your SQL statement may have a vbCrLf in it. This would cause the
break. You also must recognize that the Immediate window will break
strings, that are longer than the Immediate window width, into
separate lines. These breaks may be inside a word or phrase, thus
invalidating the SQL string.

Since you say the break is a space, that space shouldn't cause the SQL
statement to fail. Therefore, the problem is probably not in the SQL
statement, but in your VBA code. Can we see that code?

Rgds,

MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQAwmp4echKq OuFEgEQIDAACg05 FPcdwRDRwr7fHIT B2YF3RokXwAn0kL
v4CsonwtGlsAgwy rVh75hcMh
=hdEE
-----END PGP SIGNATURE-----
Colleyville Alan wrote:
"MGFoster" <me@privacy.com > wrote in message
news:aT******** **********@news read1.news.pas. earthlink.net.. .
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Are you putting spaces in the SQL statements in your VBA strings.
IOW:

strMySQL = "Select * From myTable"
strMySQL = strMySQL & "Where X = Y"

This will concatenate to

Select * From myTableWhere X = Y
^^

See the error where I didn't put a space after the myTable in the
first strMySQL assignment. This will cause an SQL syntax error when
the SQL command is attempted.

Therefore, put extra spaces at the end of your strings to ensure the
concatenati on properly separates all elements of the SQL statement.

MGFoster:::mg f00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQAo6Q4echKq OuFEgEQJ1QACg4h Egrk5utCbp/dcRlJANjyNRUxkA n0iI
ofVMmEVfaiVXy yhVbcwK4fG+
=2310
-----END PGP SIGNATURE-----
\

Yes, I'm putting in the spaces. There were a couple of errors where I had
not put in the spaces, but I got those fixed before I posted this. The
thing is, the SQL statement breaks into two lines when I copy the string
from the Immediates window to the SQL window. When I eliminate that break,
I can run the SQL from that window. I have checked the length of the
statement and now think that this could be the problem. The length of the
line that gets split is 1299 characters and it gets split into two lines of
1023 characters on one line and the 276 characters on the next line; it
seems that I have reached the end of the capacity of a string. What do I do
now? Can I use two variables to split the SQL Statement in two and then
concatenate them? How might the coding for that look?

Thanks
Colleyville Alan wrote:

I have an application that uses SQL. I am writing a new piece to it, so
I
used the same approach that worked before. I set up a string and add to
it,
i.e. strMySql = "some Sql Statement" and then strMySql = strMySql +
"some
other new statement".

The program keeps crashing saying I am running an invalid operation. I
go
to debug.print and copy the contents of the strMySql to the sql window.
Sure enough, where the sql statement wrapped in the Immdiates window,
the
statement got split to a new line in the SQL window. I take out the
space
at the end of the line and the next line snaps back into place to form a
coninuous statement once again. At this point, I can change back to the
QBE
window and the statement is set up properly and will execute. But in
VBA it
will not and I think that part that wraps in the Immdediate window has
nothing to do with my code.

Can anyone venture a guess as to what I am doing wrong?
Thanks



Nov 12 '05 #5

"MGFoster" <me@privacy.com > wrote in message
news:wE******** **********@news read1.news.pas. earthlink.net.. .
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Your SQL statement may have a vbCrLf in it.
It does now since that was the *answer* to my problem. I added it to the
end of each line, thus:

strMySql = strMySql & "Fund_Holdings_ By_Plan.Plan_Na me " & vbCrLf

This would cause the break. When it breaks this way, it does not split at the wrong point. So I can
copy all of the code from the Immediates window and it runs in the SQL
window. More importantly, it works in VBA!
You also must recognize that the Immediate window will break
strings, that are longer than the Immediate window width, into
separate lines. These breaks may be inside a word or phrase, thus
invalidating the SQL string.

Since you say the break is a space, that space shouldn't cause the SQL
statement to fail. Therefore, the problem is probably not in the SQL
statement, but in your VBA code. Can we see that code?


I have it working now, but every sql stmt was breaking in Immediates at
exactly 1023 char. When I copied the contents to the sql window, got rid of
the "blank" (basically, rejoined the line), it ran fine. Before I rejoined
the line, I got the same error msg that I had received in VBA. So while
everyone tells me that I have the problem all wrong, all of the errors in
each of 5 sql blocks were the same. And the & vbCrLf after the end of each
line fixed the problem. I'm not 100% sure what it all means, but right now
it works and I am reasonably happy.
Nov 12 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

162
7299
by: Isaac Grover | last post by:
Hi everyone, Just out of curiosity I recently pointed one of my hand-typed pages at the W3 Validator, and my hand-typed code was just ripped to shreds. Then I pointed some major sites (microsoft.com, cnn.com, etc.) at the W3 Validator; to my surprise none of them passed. Doesn't anyone care anymore, or are the standards more-or-less looked at as guidlines for web design?
11
1613
by: Richard | last post by:
www.geocities.com/r_bullis/test1.html At least this menu works in netscape. Disregarding the colors of the divisions. Those will be removed later. What I'm looking at doing is to have the "text" beside the images more centered with the image and perhaps a bit more to the right. I'm not sure if it's within the javascript, but I keep finding roadblocks to do it the way I want to.
26
8411
by: Spondishy | last post by:
Hi, I have a problem with divs and padding in IE6 and Firefox. Basically my example that I have attached works exactly how I want in IE6, but padding is treated differently in Firefox. My example is below. http://www.villas2u.com/example/test.htm http://www.villas2u.com/example/styles.css I realise that the issue is with the padding of 10px pushing the
7
1781
by: Frank-René Schäfer | last post by:
Case: -- class X has occupies tiny amount of memory: sizeof(X) is only a little greater than sizeof(void*). -- X instantiates thousands of objects and memory does matter. -- The class has a virtual destructor, and therefore, a pointer to a virtual function table.
1
1332
by: Chris | last post by:
Hi, Is it normal for dependencies found by a setup project to be included in the MSI even if they are references to DLL's in the GAC? I have several references in a project that are to GAC resources but they are being packaged up into my MSI. I thought if Copy Local was set to false, the files would not be included. Is something not right or do I not understand what is meant to happen here? Thanks for any help.
9
2186
by: Andy B | last post by:
If I bought one of these boxes/OS combos as a postgresql database server, would postgresql be able to make the best use of it with a huge (e.g. 40GB) database? Box: HP ProLiant DL585, with 4 AMD64 CPUs and 64GB of RAM. (other vendor options also exist) OS: SUSE enterprise 8 linux for AMD (links to product info at bottom)
0
2633
by: Rob Klaus | last post by:
Hello, We are having a problem where intermittently a query will not work, returning an error: ERROR: Relation "x" does not exist It will do this for a variable period, typically not lasting more than 5 minutes
11
1479
by: cj | last post by:
Public Class MyStringLogger Private Shared m_loglock As New Object Public Shared Sub Write(ByVal str As String) SyncLock (m_loglock) Dim sw As New System.io.StreamWriter("c:\validate.log", True) sw.WriteLine(str) sw.Close() End SyncLock
32
2748
by: Stephen Horne | last post by:
I've been using Visual C++ 2003 for some time, and recently started working on making my code compile in GCC and MinGW. I hit on lots of unexpected problems which boil down to the same template issue. A noddy mixin layer example should illustrate the issue... class Base { protected: int m_Field;
0
9715
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10356
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9176
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.