Microsoft KB Archive/170149: Difference between revisions
m (Text replacement - """ to """) |
m (Text replacement - "&" to "&") |
||
Line 109: | Line 109: | ||
'This SQL Statement cause Run-time error 3075. | 'This SQL Statement cause Run-time error 3075. | ||
SQLStr = "Select PubID, Name, [Company Name], Address, " _ | SQLStr = "Select PubID, Name, [Company Name], Address, " _ | ||
& | & "City, State, PubID, Name, [Company Name], Address, City, " _ | ||
& | & "State, PubID, Name, [Company Name], Address, City, State, " _ | ||
& | & "PubID, Name, [Company Name], Address, City, State " _ | ||
& | & "from Publishers Where PubID = 2 and State = 'MA'" | ||
'This SQL Statement cause Run-time error 3061. | 'This SQL Statement cause Run-time error 3061. | ||
'SQLStr = "Select PubID, Name, [Company Name], Address, City, " _ | 'SQLStr = "Select PubID, Name, [Company Name], Address, City, " _ | ||
' & | ' & "State, PubID, Name, [Company Name], Address, City, State, " _ | ||
' & | ' & "PubID, Name, [Company Name], Address, City, State, " _ | ||
' & | ' & "PubID, Name, [Company Name], Address, City, State, " _ | ||
' & | ' & "PubID from Publishers Where PubID = 2 and State = 'MA'" | ||
Set RS = DB.OpenRecordset(SQLStr, dbOpenDynaset) | Set RS = DB.OpenRecordset(SQLStr, dbOpenDynaset) |
Latest revision as of 12:29, 21 July 2020
Article ID: 170149
Article Last Modified on 7/15/2004
APPLIES TO
- Microsoft Visual Basic 5.0 Learning Edition
- Microsoft Visual Basic 6.0 Learning Edition
- Microsoft Visual Basic 5.0 Professional Edition
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Visual Basic 5.0 Enterprise Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
- Microsoft Visual Basic 4.0 Standard Edition
- Microsoft Visual Basic 4.0 Professional Edition
- Microsoft Visual Basic 4.0 Professional Edition
- Microsoft Visual Basic 4.0 16-bit Enterprise Edition
- Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
This article was previously published under Q170149
SYMPTOMS
The Name property of a DAO Recordset object is limited to 256 characters. It only reports the first 256 characters of the SQL statement used to create the new Recordset. If the SQL statement is longer than 256 characters, and you refresh the Data Control in the code later on, you will receive one of the following errors:
CAUSE
When you set the Data Control's Recordset property to an existing Recordset, it obtains its RecordSource property from the DAO Recordset's Name property, which allows a maximum length of 256 characters.
RESOLUTION
Store the SQL statement into a string variable. Before refreshing the Data Control, set its RecordSource Property to this variable. For example:
Data1.RecordSource = SQLStr Data1.Refresh
STATUS
This behavior is by design.
MORE INFORMATION
Steps to Reproduce Behavior
- Start a new project in Visual Basic. Form1 is created by default.
- Add a Data Control(Data1) and a CommandButton (Command1) to Form1.
In the Click event of Command1, place the following code:
Private Sub Command1_Click() Dim DB As Database, RS As Recordset Dim SQLStr As String Set DB = DBEngine.Workspaces(0).OpenDatabase("Biblio.MDB") 'This SQL Statement cause Run-time error 3075. SQLStr = "Select PubID, Name, [Company Name], Address, " _ & "City, State, PubID, Name, [Company Name], Address, City, " _ & "State, PubID, Name, [Company Name], Address, City, State, " _ & "PubID, Name, [Company Name], Address, City, State " _ & "from Publishers Where PubID = 2 and State = 'MA'" 'This SQL Statement cause Run-time error 3061. 'SQLStr = "Select PubID, Name, [Company Name], Address, City, " _ ' & "State, PubID, Name, [Company Name], Address, City, State, " _ ' & "PubID, Name, [Company Name], Address, City, State, " _ ' & "PubID, Name, [Company Name], Address, City, State, " _ ' & "PubID from Publishers Where PubID = 2 and State = 'MA'" Set RS = DB.OpenRecordset(SQLStr, dbOpenDynaset) Set Data1.Recordset = RS Debug.Print RS.Name Debug.Print Data1.RecordSource Data1.Refresh End Sub
- Start the program by pressing the F5 key.
- Click the Command1 button to execute the code. You will receive one of the errors listed above.
Additional query words: kbVBp400 kbVBp500 kbVBp600 kbdse kbDSupport kbVBp kbrdo
Keywords: kbprb KB170149