Results 1 to 4 of 4
  1. #1
    rivereridanus is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    71

    counting columns of table to view in dynamic recordset

    Hello!

    I have some code here to run dynamic SQL code from a text box that user types into. It runs fine and returns the recordset for viewing in the listbox lstResult. However, it only returns the first column of the results. I know I need a .ColumnCount = something property, but I don't know how to go about actually counting them! Please help!



    Private Sub cmdrunquery_Click()
    Dim dbsMenuStudy As DAO.Database
    Dim rs As DAO.Recordset
    Dim strSQL As String

    Set dbsMenuStudy = Currentdb
    strSQL = Me.txtSQL
    Set rs = dbsMenuStudy.OpenRecordset(strSQL)

    With Me.lstResult

    Set rs = dbsMenuStudy.OpenRecordset(strSQL)

    If rs.RecordCount > 0 Then
    .RowSourceType = "Table/Query"
    .RowSource = strSQL
    .Enabled = True
    'display * fields
    .ColumnCount =
    .ColumnHeads = True

    Else
    .ColumnCount = 1
    .RowSourceType = "Value List"
    .RowSource = "No records found."

    End If
    End With

    End Sub

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Try

    rs.Fields.Count
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    rivereridanus is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    71
    Thank you so much!

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    No problemo!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Missing Columns in Datasheet View
    By mikel in forum Access
    Replies: 3
    Last Post: 01-02-2015, 01:57 PM
  2. Replies: 4
    Last Post: 04-09-2011, 10:39 AM
  3. Dynamic Check Boxes values from table
    By ktmjamal in forum Forms
    Replies: 1
    Last Post: 02-21-2011, 07:49 AM
  4. Replies: 10
    Last Post: 02-06-2010, 10:50 PM
  5. Replies: 3
    Last Post: 01-21-2010, 08:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums