473,545 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with large amount of characters in a VBA variant


Hello,

I work on an app developped with Access/VBA and communicating with a
SQL Server database via ODBC.

My problem is that I have to manage a big string which can be 0 to
1024 characters long. The string is correctly stored in the Access and
SQL Server tables (Memo field for Access, and varchar(1024) for SQL
Server).

I also need to write this string in an Excel report created by the
application. For this purpose, I store the huge string in a variant
VBA variable, but when looking at the variant with the debugger, I
find that it has got only 255 characters (when the string is 1024
characters long). In the Excel report, I also get only the 255 first
chars.

Is this a normal behaviour ? I searched the internet but I didn't find
information about the max string length that can be stored in a
variant in VBA ?

Thank you for your help.
Jan 3 '08 #1
11 9114
Greetings,

The problem is with the ODBC connection. With an ODBC connection to an
Access MDB you will only get 255 chars per field max for Text (varchar)
columns. The rest of the characters get truncated. The way to get
around this limitation with ODBC is to retrieve the desired values using
ADO (in VBA). Go to Tools/References and make a reference to the
highest version of

"Microsoft ActiveX Data Objects 2.X Library"

then, in a Standard Code module (or a Form code module)

Sub GetLongString()
Dim cmd As New ADODB.Command, RS As New ADODB.Recordset
cmd.ActiveConne ction = "Provider=SQLOL EDB; Data
Source=yourServ er;Database=you rDB;Trusted_Con nection=Yes"
cmd.ActiveConne ction.CursorLoc ation = adUseClient
cmd.CommandTime out = 600
cmd.CommandType = adCmdText
cmd.CommandText = "Select fldx from tblX Where something = 'something'"
Set RS = cmd.Execute
Debug.Print RS(0)
cmd.ActiveConne ction.Close
End Sub

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jan 3 '08 #2
On 3 jan, 18:29, Rich P <rpng...@aol.co mwrote:
Greetings,

The problem is with the ODBC connection. *With an ODBC connection to an
Access MDB you will only get 255 chars per field max for Text (varchar)
columns. *The rest of the characters get truncated. *The way to get
around this limitation with ODBC is to retrieve the desired values using
ADO (in VBA). *Go to Tools/References and make a reference to the
highest version of

"Microsoft ActiveX Data Objects 2.X Library"

then, in a Standard Code module (or a Form code module)

Sub GetLongString()
Dim cmd As New ADODB.Command, RS As New ADODB.Recordset
cmd.ActiveConne ction = "Provider=SQLOL EDB; Data
Source=yourServ er;Database=you rDB;Trusted_Con nection=Yes"
cmd.ActiveConne ction.CursorLoc ation = adUseClient
cmd.CommandTime out = 600
cmd.CommandType = adCmdText
cmd.CommandText = "Select fldx from tblX Where something = 'something'"
Set RS = cmd.Execute
Debug.Print RS(0)
cmd.ActiveConne ction.Close
End Sub

Rich

*** Sent via Developersdexht tp://www.developersd ex.com***
Hello,

Thank you for your answer. I am not sure the problem comes from the
ODBC connexion, as the data in the Excel report is sent from the
Access application via Automation, after creating an Excel report via
the following code :

Set oEXCEL_EXP = oExcel_App.Work books.Add(xlWBA TWorksheet)

Is there a possibility that the data is truncated during the
communication process between Access and Excel ?

Thank you.

Jan 3 '08 #3
No. Whatever data you pass from Access to Excel will remain the same.
The problem is that the automation code is reading the data from an ODBC
table and the data is being truncated at the ODBC table.

One thing you could do to simplify this data transfer is to write the
same ADO code I posted in Excel in Excel's visual Basic Editor. Make
the same reference to

Microsoft ActiveX Data Objects 2.X Library

and add the code to a code module. This will be a Macro in Excel.

cmd.CommandText = "Select * from tblx"

the ADO command object will use the same connection string to your sql
server as the connection string in Access.

So Access is basically the middle man for this data transfer. You are
really transferring data from the Sql Server to Excel. It is much
simpler to bypass the middle man (Access). Even if your situation would
not be conducive to using Excel programming I would give that a try so
you can see how it works. Here is some sample code that you would use
in Excel:

Sub GetDataFromSqlS erver()
Dim cmd As New ADODB.Command, RS As New ADODB.Recordset
Dim rng As Range, i As Integer
Dim strSql As String, WkBk As Workbook, sht As Worksheet

strSql = "SELECT * FROM yourTbl WHERE something = 'something'"

Set WkBk = ActiveWorkbook
Set sht = WkBk.ActiveShee t

Set rng = sht.Range("A1:B H1")

cmd.ActiveConne ction = "Provider=SQLOL EDB; Data
Source=yourServ er;Database=you rDB;Trusted_Con nection=Yes"
cmd.ActiveConne ction.CursorLoc ation = adUseClient
cmd.CommandType = adCmdText
cmd.CommandText = strSql
DoEvents
Set RS = cmd.Execute
sht.Range("A2") .CopyFromRecord set RS

For i = 0 To RS.Fields.Count - 1
rng(1, i + 1) = RS(i).Name
Next
rng.Font.Bold = True
rng.Font.ColorI ndex = 5
End Sub

The connection string here is based on Windows authentication. If this
connection string doesn't work then try using your UserID and Password
as follows

cmd.ActiveConne ction = "Provider=SQLOL EDB; Data
Source=yourServ er;Database=you rDB;uid=steve;p wd=test"

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jan 3 '08 #4
Rich P <rp*****@aol.co mwrote in
news:47******** *************@n ews.qwest.net:
No. Whatever data you pass from Access to Excel will remain the
same. The problem is that the automation code is reading the data
from an ODBC table and the data is being truncated at the ODBC
table.
Absolutely Bull$#it.
Microsoft acknowledge the problem and proveide some workarounds at
http://support.microsoft.com/kb/208801
Rich, go away. Don't go away mad, jut go away.
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jan 4 '08 #5
nartla <br**********@a ltran.comwrote in
news:0a098301-faf3-4ef8-be89-4e1f0dc0c2c4
@u10g2000prn.go oglegroups.co
m:
>
Hello,

I work on an app developped with Access/VBA and communicating with
a SQL Server database via ODBC.

My problem is that I have to manage a big string which can be 0 to
1024 characters long. The string is correctly stored in the Access
and SQL Server tables (Memo field for Access, and varchar(1024)
for SQL Server).

I also need to write this string in an Excel report created by the
application. For this purpose, I store the huge string in a
variant VBA variable, but when looking at the variant with the
debugger, I find that it has got only 255 characters (when the
string is 1024 characters long). In the Excel report, I also get
only the 255 first chars.

Is this a normal behaviour ? I searched the internet but I didn't
find information about the max string length that can be stored in
a variant in VBA ?

Thank you for your help.
See the Microsoft Knowledgebase article at
http://support.microsoft.com/kb/208801
--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jan 4 '08 #6
On 4 jan, 00:51, Bob Quintal <rquin...@sPAmp atico.cawrote:
nartla <bruno.bar...@a ltran.comwrote in
news:0a098301-faf3-4ef8-be89-4e1f0dc0c2c4
@u10g2000prn.go oglegroups.co
m:


Hello,
I work on an app developped with Access/VBA and communicating with
a SQL Server database via ODBC.
My problem is that I have to manage a big string which can be 0 to
1024 characters long. The string is correctly stored in the Access
and SQL Server tables (Memo field for Access, and varchar(1024)
for SQL Server).
I also need to write this string in an Excel report created by the
application. For this purpose, I store the huge string in a
variant VBA variable, but when looking at the variant with the
debugger, I find that it has got only 255 characters (when the
string is 1024 characters long). In the Excel report, I also get
only the 255 first chars.
Is this a normal behaviour ? I searched the internet but I didn't
find information about the max string length that can be stored in
a variant in VBA ?
Thank you for your help.

See the Microsoft Knowledgebase article athttp://support.microso ft.com/kb/208801

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account fromhttp://www.teranews.co m- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -
Thank you for your help.

Jan 4 '08 #7
Bob,

I have read several of your posts, and you do seem to posses proficiency
in the VBA world, but you have also stated that your proficiency is
limited to VBA. I am proficient in VBA and also quite proficient in
VB.Net and C#, and even though some of my suggestions may go from point
A to point D (versus A to B to C to D) they are valid suggestions. I
post in this newsgroup to stay current with VBA since most of my
projects consist of migrating VBA projects to the enterprise
environment.

Yes, it is a little perturbing when those of you with expertise limited
to one field have to be critical with those of us who have extensively
more experience and expertise in a number of fields, but I guess it goes
with the territory.

I have already trained myself to not offer .Net solutions in this NG
even though .Net significantly reduces the amount of sphaghetti code
required for solutions in VBA. In this particular post, the poster is
transferring data from Sql SErver to Excel via Access and is having
problems. I am suggesting to bypass Access altogether as an experiment.
Be realistic -- Access is a micro RDBMS with all the limitations that
come with being Micro (thus I have to migrate all sorts of VBA projects
to .Net).

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jan 4 '08 #8
Rich P <rp*****@aol.co mwrote in news:477e8793$0 $10309$815e3792
@news.qwest.net :
Bob,

I have read several of your posts, and you do seem to posses proficiency
in the VBA world, but you have also stated that your proficiency is
limited to VBA. I am proficient in VBA and also quite proficient in
VB.Net and C#, and even though some of my suggestions may go from point
A to point D (versus A to B to C to D) they are valid suggestions. I
post in this newsgroup to stay current with VBA since most of my
projects consist of migrating VBA projects to the enterprise
environment.

Yes, it is a little perturbing when those of you with expertise limited
to one field have to be critical with those of us who have extensively
more experience and expertise in a number of fields, but I guess it goes
with the territory.

I have already trained myself to not offer .Net solutions in this NG
even though .Net significantly reduces the amount of sphaghetti code
required for solutions in VBA. In this particular post, the poster is
transferring data from Sql SErver to Excel via Access and is having
problems. I am suggesting to bypass Access altogether as an experiment.
Be realistic -- Access is a micro RDBMS with all the limitations that
come with being Micro (thus I have to migrate all sorts of VBA projects
to .Net).
I'm with Bob. IMO you have little knowledge, and less skill, but you post
here frequently in an authoritative manner. As your posts are both verbose
and illogical, it often is too much trouble to refute them.
I think you should limit your posts to brief suggestions for specific
questions.

And it would be fine with me if you filed Developersdex in the appropriate
aperture.
Jan 4 '08 #9
Rich, being proficient would mean refraining from posting abso;ute
hogwash, as you did to trigger my response to your post.

You said " No. Whatever data you pass from Access to Excel will
remain the same." Microsoft themselves say otherwise. That's a lack
of proficiency on your part.

You said "the data is being truncated at the ODBC table." That is an
incorrect statement. As someone who deals with memo fields in tables
upsized to text in SQL Server I will attest to that.

What I ask is you stop posting stuff that misleads those people
looking for a solution to their problem.

Sincerely,

Bob Quintal.
Rich P <rp*****@aol.co mwrote in
news:47******** *************** @news.qwest.net :
Bob,

I have read several of your posts, and you do seem to posses
proficiency in the VBA world, but you have also stated that your
proficiency is limited to VBA. I am proficient in VBA and also
quite proficient in VB.Net and C#, and even though some of my
suggestions may go from point A to point D (versus A to B to C to
D) they are valid suggestions. I post in this newsgroup to stay
current with VBA since most of my projects consist of migrating
VBA projects to the enterprise environment.

Yes, it is a little perturbing when those of you with expertise
limited to one field have to be critical with those of us who have
extensively more experience and expertise in a number of fields,
but I guess it goes with the territory.

I have already trained myself to not offer .Net solutions in this
NG even though .Net significantly reduces the amount of sphaghetti
code required for solutions in VBA. In this particular post, the
poster is transferring data from Sql SErver to Excel via Access
and is having problems. I am suggesting to bypass Access
altogether as an experiment. Be realistic -- Access is a micro
RDBMS with all the limitations that come with being Micro (thus I
have to migrate all sorts of VBA projects to .Net).

Rich

*** Sent via Developersdex http://www.developersdex.com ***


--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Jan 4 '08 #10

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

Similar topics

14
42364
by: deko | last post by:
Is there a way to check user input for illegal characters? For example, a user enters something into a text box and clicks OK. At that point I'd like to run code such as this: illegal = Array(\, /, :, *, ?, ", <, >, |) If Me.TextBox Contains illegal Then MsgBox "You entered illegal characters. Please try again." Me.TextBox = Null
6
2357
by: Peter Hickman | last post by:
I have a program that requires x strings all of y length. x will be in the range of 100-10000 whereas the strings will all be < 200 each. This does not need to be grown once it has been created. Should I allocate x strings of y length or should I allocate a single string x * y long? Which would be more efficient and / or portable? Thank...
9
35232
by: haibhoang | last post by:
I have a Windows Service that is trying to parse a large (> 1Gig) text file. I am keep getting OutOfMemoryException exception. Here is the code that's having problem: using (StreamReader streamReader = new StreamReader(stream, Encoding.ASCII)) { string line = ""; DateTime currentDate = DateTime.Now.Date; while (streamReader.Peek() > -1)
0
3916
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header,...
9
4090
by: mupe | last post by:
Hi, i have a problem with a Type Library, which is written in C++. I am developing an application in C#.NET and have to use functions from this COM-Type Library. When I use these functions in the "old" VB it works but not in .NET. I think it is a problem with marshalling but I could not find a solution yet. First I included the Type...
4
6677
by: loretta | last post by:
I have data within an xml tag that is being truncated when being read into a javascript variable. On Firefox, I am only getting up to 4096 characters. On IE, I am getting 31324 characters. I can view the xml source, all the data is there. I am using javascript function getElementsByTagName to read the data from the tag and then the firstChild...
22
3195
by: roadrunner | last post by:
Hi, Our website has recently been experiencing some problems under load. We have pinpointed a particular function which slows dramatically when we have these problems. Normally it should execute in under a second but it rises to about one minute under duress. The code is fairly straight forward with no calls to databases or any other...
0
2319
by: jayohare | last post by:
Hello, I have code within my DB application to process credit cards through authorize.net. Ive been using the same code for several years without a problem. I have an order entry computer and after reinstalling Win XP, we used Office/Access 2003. When we try to process CC's we get a debug screen and Access itself crashes. However, the code...
9
2464
by: brendanmcdonagh | last post by:
Hi, I am designing a project for my friend as I am just a week old baby to vb and want to implement what I've learnt so far. She wants to be able to put start time, end time and lunch for each day and then calculate amount of hours worked. So far I have designed form and added code to calculate textbox inputs, (which works!). However, I...
0
7473
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...
0
7406
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...
0
7813
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...
0
7761
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4949
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...
0
3444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1888
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1020
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
709
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.