Results 1 to 5 of 5

Thread: code assistant

  1. #1
    Join Date
    Jun 2012
    Posts
    85

    Unanswered: code assistant

    Hey, i have some code here to get tables into a combo box on my form when i click a button to refresh the list in my combo box.

    Code:
    Private Function GetTables()
    
    Dim Myarray As Variant
    Dim TablesSchema As adodb.Recordset
    Dim conn As adodb.Connection
    
    'reset cursorlocation to allow sorting in ordinal_position
       Set conn = CurrentProject.Connection
       With conn
       .CursorLocation = adUseClient
       End With
       
    'Get all database tables.
     Set TablesSchema = conn.OpenSchema(adSchemaTables)
     TablesSchema.Sort = ("TABLE_NAME")
     
     Me.cboTablesList.RowSource() = ""
     Do While Not TablesSchema.EOF
     
     'Exclude System Tables and Default Treeview Table
     If Left(TablesSchema("TABLE_NAME"), 4) = "MSYS" Or TablesSchema("TABLE_NAME") = "TREEVIEWFEED" Or Left(TablesSchema("TABLE_NAME"), 1) = "~" Then
     GoTo SKIP
     End If
     
            'Add Tables to the Combobox
            Myarray = Me.cboTablesList.RowSource()
            If Me.cboTablesList.ListCount < 1 Then
            Me.cboTablesList.RowSource = TablesSchema("TABLE_NAME")
            Else
            Me.cboTablesList.RowSource = Myarray & ";" & TablesSchema("TABLE_NAME")
            End If
    SKIP:
     TablesSchema.MoveNext
     Loop
    
    
    Set TablesSchema = Nothing
    End Function
    But i can t get it to run past the first 4 lines

    Thanks
    Mike
    ________

  2. #2
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    runs perfectly fine in my test database. What error are you getting, and where?

    Steve

  3. #3
    Join Date
    Jun 2012
    Posts
    85
    right at the start. error pops up, and it selects

    Dim TablesSchema As adodb.Recordset

    I tried going tools, resources, and check the settings in there. but im just completely baffled right now
    Mike
    ________

  4. #4
    Join Date
    Aug 2004
    Location
    Cary, NC
    Posts
    264
    If you go to Tools -> References, do you have the Microsoft ActiveX Data Objects library selected? Removing that one mine gives me user defined type error, is that the error you are getting? If the references don't solve the problem please post the error message.

    Steve

  5. #5
    Join Date
    Jun 2012
    Posts
    85
    thanks, appreciate the help got it working!
    Mike
    ________

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •