473,396 Members | 2,106 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,396 software developers and data experts.

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 1711
-----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:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQAo6Q4echKqOuFEgEQJ1QACg4hEgrk5utCbp/dcRlJANjyNRUxkAn0iI
ofVMmEVfaiVXyyhVbcwK4fG+
=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******************@newsread1.news.pas.earth link.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:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQAo6Q4echKqOuFEgEQJ1QACg4hEgrk5utCbp/dcRlJANjyNRUxkAn0iI
ofVMmEVfaiVXyyhVbcwK4fG+
=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:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQAwmp4echKqOuFEgEQIDAACg05FPcdwRDRwr7fHITB2YF3 RokXwAn0kL
v4CsonwtGlsAgwyrVh75hcMh
=hdEE
-----END PGP SIGNATURE-----
Colleyville Alan wrote:
"MGFoster" <me@privacy.com> wrote in message
news:aT******************@newsread1.news.pas.earth link.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:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

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

iQA/AwUBQAo6Q4echKqOuFEgEQJ1QACg4hEgrk5utCbp/dcRlJANjyNRUxkAn0iI
ofVMmEVfaiVXyyhVbcwK4fG+
=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******************@newsread1.news.pas.earth link.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_Name " & 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
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...
11
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...
26
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...
7
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...
1
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...
9
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 ...
0
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...
11
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",...
32
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...
0
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...
0
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,...

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.