ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SQL limit of 255 characters (https://www.excelbanter.com/excel-programming/347652-sql-limit-255-characters.html)

DB

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.


Jim Thomlinson[_4_]

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.


DB

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.



All times are GMT +1. The time now is 08:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com