Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rating: Thread Rating: 10 votes, 5.00 average. Display Modes
Old 08-07-2008, 08:30 AM   #1
darkmastergyz
Registered User
 
Join Date: May 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
darkmastergyz is on a distinguished road
Max length of a string?

I have a string in VBA (it's dim as string), and it's truncating everything longer than 252 characters or so... Is there a length limit on a string?

darkmastergyz is offline   Reply With Quote
Old 08-07-2008, 08:39 AM   #2
rainman89
I cant find the any key..
 
rainman89's Avatar
 
Join Date: Feb 2007
Location: New York
Posts: 3,023
Thanks: 1
Thanked 6 Times in 6 Posts
rainman89 has a spectacular aura about rainman89 has a spectacular aura about
255 char usually
__________________
-Ray
rainman89 is offline   Reply With Quote
Old 08-07-2008, 08:50 AM   #3
georgedwilkinson
AWF VIP
 
Join Date: Mar 2008
Location: Houston, TX USA!!!
Posts: 3,857
Thanks: 0
Thanked 7 Times in 7 Posts
georgedwilkinson has a spectacular aura about georgedwilkinson has a spectacular aura about
Hmmm. I've had VB strings much longer than 255 bytes. What are you doing with the string?

I have had problems copying data longer than 255 bytes from Access to Excel, but it is not because of the limitation of a String's size.

__________________
Thanks,
George Wilkinson
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
georgedwilkinson is offline   Reply With Quote
Old 08-07-2008, 08:51 AM   #4
darkmastergyz
Registered User
 
Join Date: May 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
darkmastergyz is on a distinguished road
Is there anyway to get around it....it's blowing up my app right now
darkmastergyz is offline   Reply With Quote
Old 08-07-2008, 10:27 AM   #5
darkmastergyz
Registered User
 
Join Date: May 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
darkmastergyz is on a distinguished road
How to have a string longer than 255 chars

I have a string right now which needs to hold about 1000 characters or so. But, VBA limits it to only 255 characters. What can I do to make it hold more? (the string holds a SQL string which then gets passed to: db.openrecordset(sqlstr, dbopensnapshot)


Thanks
darkmastergyz is offline   Reply With Quote
Old 08-07-2008, 10:40 AM   #6
The_Doc_Man
AWF VIP
 
Join Date: Feb 2001
Location: New Orleans, LA, USA
Posts: 7,852
Thanks: 14
Thanked 91 Times in 87 Posts
The_Doc_Man is a glorious beacon of light The_Doc_Man is a glorious beacon of light The_Doc_Man is a glorious beacon of light The_Doc_Man is a glorious beacon of light The_Doc_Man is a glorious beacon of light
Strictly speaking, I don't recall that VBA limits string size to 255. I thought it was 65535 or something like that. But some of the interfaces that pass strings DO limit string size. If you could create an SQL query separately and THEN open it by name, that might be one workaround. I think you can build a long query, you just can't pass one.
__________________
I'm a certified grandpa and proud of it.
Not quite so valuable after the MVP status expired.
CompTIA Security+ certified.
The_Doc_Man is offline   Reply With Quote
Old 08-07-2008, 10:43 AM   #7
georgedwilkinson
AWF VIP
 
Join Date: Mar 2008
Location: Houston, TX USA!!!
Posts: 3,857
Thanks: 0
Thanked 7 Times in 7 Posts
georgedwilkinson has a spectacular aura about georgedwilkinson has a spectacular aura about
Don't post the same question twice!

http://www.access-programmers.co.uk/...d.php?t=154582

__________________
Thanks,
George Wilkinson
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
georgedwilkinson is offline   Reply With Quote
Old 08-07-2008, 10:49 AM   #8
georgedwilkinson
AWF VIP
 
Join Date: Mar 2008
Location: Houston, TX USA!!!
Posts: 3,857
Thanks: 0
Thanked 7 Times in 7 Posts
georgedwilkinson has a spectacular aura about georgedwilkinson has a spectacular aura about
I take it you no longer want this question answered since you created a new post.
__________________
Thanks,
George Wilkinson
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
georgedwilkinson is offline   Reply With Quote
Old 08-07-2008, 11:51 AM   #9
rainman89
I cant find the any key..
 
rainman89's Avatar
 
Join Date: Feb 2007
Location: New York
Posts: 3,023
Thanks: 1
Thanked 6 Times in 6 Posts
rainman89 has a spectacular aura about rainman89 has a spectacular aura about
i dont read well, i thought it was to a text box..... i need to start paying attention
__________________
-Ray
rainman89 is offline   Reply With Quote
Old 08-07-2008, 12:28 PM   #10
darkmastergyz
Registered User
 
Join Date: May 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
darkmastergyz is on a distinguished road
Umm.... I'm not doing anything to it right now. If I just have a string, and assign it a value:

eg.

dim str1 as string
str1 = "[something 252 characters]"

It doesn't hold anything past the first 252 characters....
darkmastergyz is offline   Reply With Quote
Old 08-07-2008, 12:35 PM   #11
georgedwilkinson
AWF VIP
 
Join Date: Mar 2008
Location: Houston, TX USA!!!
Posts: 3,857
Thanks: 0
Thanked 7 Times in 7 Posts
georgedwilkinson has a spectacular aura about georgedwilkinson has a spectacular aura about
Can you post your entire code, including whatever code calls the code in question, if pertinent to the problem? I'd really love to see this resolved for you.
__________________
Thanks,
George Wilkinson
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
georgedwilkinson is offline   Reply With Quote
Old 08-07-2008, 01:09 PM   #12
darkmastergyz
Registered User
 
Join Date: May 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
darkmastergyz is on a distinguished road
Thanks very much!

This is how I have it:

Code:
dim var1 as string
var1 = "PUT A LONG LONG THING HERE"

when I look at the var1 under watches, it doesn't show the whole thing
darkmastergyz is offline   Reply With Quote
Old 08-07-2008, 01:41 PM   #13
georgedwilkinson
AWF VIP
 
Join Date: Mar 2008
Location: Houston, TX USA!!!
Posts: 3,857
Thanks: 0
Thanked 7 Times in 7 Posts
georgedwilkinson has a spectacular aura about georgedwilkinson has a spectacular aura about
The watches are limited in how much data they can show.
__________________
Thanks,
George Wilkinson
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
georgedwilkinson is offline   Reply With Quote
Old 08-07-2008, 02:06 PM   #14
Banana
split with a cherry atop.
 
Join Date: Sep 2005
Posts: 6,319
Thanks: 0
Thanked 70 Times in 61 Posts
Banana is a glorious beacon of light Banana is a glorious beacon of light Banana is a glorious beacon of light Banana is a glorious beacon of light Banana is a glorious beacon of light Banana is a glorious beacon of light
As mentioned earlier, some methods may truncate to first 255 characters, but the VBA string is definitely capable of holding much more than 255. This says that string can hold up to 2 billion characters (e.g. limited by a Long Integer, presumably.)

But! Text data type you used in table design only can hold up to 255 character. Using Memo will allow up to what I assume is limited by Integer (65,535 characters). Thanks, Allen..

Therefore, the effective limit is 65,535 characters per memo column, though VBA is perfectly capable of holding much more than that.

Also, I suspect that Immediate Windows will also truncate string if one used debug.print, but will have to test this.

You would be better off by testing something like this:

Pseduocode:

Code:
Dim stringer As String
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset ("SomefancypantqueryReturningAColumnOfMemo")

If Not rst.BOF And Not rst.EOF Then
     stringer=rst.Fields(0)
     Debug.Print Len(stringer) 'How long is this string?
     Debug.print stringer 'See if we can read the whole string
End If
__________________
If relation-valued attributes and arbitrarily complex types are wrong, then I don't wanna to be right!
Founder of 'Blame the Developers First' crowd.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Banana is offline   Reply With Quote
Old 08-07-2008, 03:04 PM   #15
CyberLynx
Stuck On My Opinions
 
Join Date: Jan 2008
Posts: 585
Thanks: 0
Thanked 4 Times in 4 Posts
CyberLynx will become famous soon enough
Code:
dim var1 as string
var1 = "PUT A LONG LONG THING HERE"

MsgBox "String Length =  " & Len(var1) & vbCr & vbCr & var1
Even though the MsgBox will also truncate real long strings, it should be good enough to view most SQL Statements.

.

__________________
Self taught in all Environments.....and it shows
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
CyberLynx is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating/Editing Tables yeatmanj Modules & VBA 10 10-12-2006 12:34 PM
Filecopy accessman2 Modules & VBA 4 05-01-2006 10:21 AM
Import word document Rmaster Modules & VBA 3 03-08-2005 10:44 PM
Working with an ini file doulostheou Modules & VBA 3 08-21-2002 06:14 AM




All times are GMT -8. The time now is 01:52 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
(c) copyright 2010 Access World