Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
DB DB is offline
external usenet poster
 
Posts: 46
Default SQL limit of 255 characters

Anyone,

I have a user form in Excel where the user can type a description in a
textbox. I wrote SQL INSERT query in VBA to write the description to a
closed workbook that acts as a database file. Im using the ADO reference
2.7. When the text exceeds 255 characters I receive an error. I know an
Excel cell can hold more than 32k characters, how can I get the text from the
SQL statement to write to the cell in the closed workbook? Another issue Im
having is the SQL errors when a single quote is typed, is there a simple fix
for this?

I look forward to some help.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default SQL limit of 255 characters

In response to the 255 limit you just need to break up your select statement
and pass it in as concatenated arguments. Here is some really generic code I
use...

Private Const m_cDBLocation As String = "C:\MyDatabase.mdb"

Public Function RunQuery(ByVal strSelect As String, ByVal strFrom As String, _
ByVal strWhere As String, ByVal strOrderBy, ByVal blnConnected As Boolean)
As ADODB.Recordset
Dim strConnection As String

strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
m_cDBLocation & ";"

Set RunQuery = New ADODB.Recordset
With RunQuery
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
End With

RunQuery.Open strSelect & " " & strFrom & " " & strWhere & " " &
strOrderBy, strConnection, , , adCmdText
If blnConnected = False Then Set RunQuery.ActiveConnection = Nothing
End Function

Sub Example()
Dim rst As ADODB.Recordset

Set rst = RunQuery("Select *", "From tblRegions", "", ";", False)

End Sub

--
HTH...

Jim Thomlinson


"DB" wrote:

Anyone,

I have a user form in Excel where the user can type a description in a
textbox. I wrote SQL INSERT query in VBA to write the description to a
closed workbook that acts as a database file. Im using the ADO reference
2.7. When the text exceeds 255 characters I receive an error. I know an
Excel cell can hold more than 32k characters, how can I get the text from the
SQL statement to write to the cell in the closed workbook? Another issue Im
having is the SQL errors when a single quote is typed, is there a simple fix
for this?

I look forward to some help.

  #3   Report Post  
Posted to microsoft.public.excel.programming
DB DB is offline
external usenet poster
 
Posts: 46
Default SQL limit of 255 characters

Jim,
This is not the issue. The length of the text variable for the textbox
(me.txbDesc.text) is over 255 characters and causes the error. Are there ADO
methods to make this work?

"Jim Thomlinson" wrote:

In response to the 255 limit you just need to break up your select statement
and pass it in as concatenated arguments. Here is some really generic code I
use...

Private Const m_cDBLocation As String = "C:\MyDatabase.mdb"

Public Function RunQuery(ByVal strSelect As String, ByVal strFrom As String, _
ByVal strWhere As String, ByVal strOrderBy, ByVal blnConnected As Boolean)
As ADODB.Recordset
Dim strConnection As String

strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" &
m_cDBLocation & ";"

Set RunQuery = New ADODB.Recordset
With RunQuery
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
End With

RunQuery.Open strSelect & " " & strFrom & " " & strWhere & " " &
strOrderBy, strConnection, , , adCmdText
If blnConnected = False Then Set RunQuery.ActiveConnection = Nothing
End Function

Sub Example()
Dim rst As ADODB.Recordset

Set rst = RunQuery("Select *", "From tblRegions", "", ";", False)

End Sub

--
HTH...

Jim Thomlinson


"DB" wrote:

Anyone,

I have a user form in Excel where the user can type a description in a
textbox. I wrote SQL INSERT query in VBA to write the description to a
closed workbook that acts as a database file. Im using the ADO reference
2.7. When the text exceeds 255 characters I receive an error. I know an
Excel cell can hold more than 32k characters, how can I get the text from the
SQL statement to write to the cell in the closed workbook? Another issue Im
having is the SQL errors when a single quote is typed, is there a simple fix
for this?

I look forward to some help.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Limit to 5 characters... Astro Excel Worksheet Functions 2 January 20th 09 03:00 AM
How do I limit characters in a cell? casey Excel Worksheet Functions 5 October 4th 06 01:33 AM
limit of characters in Excell Jola Excel Discussion (Misc queries) 1 September 20th 06 10:52 AM
limit no of characters in cell rocket0612 Excel Discussion (Misc queries) 3 June 1st 05 07:11 PM
Can I limit a cell to 72 characters? How? Chris Excel Discussion (Misc queries) 2 December 28th 04 04:57 PM


All times are GMT +1. The time now is 01:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"