PRB: Recordset Name Property is Limited to 256 Characters

Last reviewed: July 14, 1997
Article ID: Q170149
The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0
  • Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 16-bit and 32-bit, for Windows, version 4.0

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:

   "Run-time error '3061': Too few parameters. Expected 1."

   "Run-time error '3075': Syntax error in string in query expression
   'xxxx'."

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

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Add a Data Control(Data1) and a CommandButton (Command1) to Form1.

  3. 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
    
    

  4. Start the program by pressing the F5 key.

  5. Click the Command1 button to execute the code. You will receive one of the errors listed above.


Keywords : kberrmsg vb4all vb4win vb5all VBKBDAO VBKBDB VBKBJet VBKBObj
Version : 4.0 5.0
Platform : WINDOWS
Issue type : kbprb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 14, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.