Connecting Tech Pros Worldwide Forums | Help | Site Map

Access VBA - CurrentDb.Recordsets is empty

Member
 
Join Date: Mar 2007
Location: Columbus, OH
Posts: 69
#1: Mar 21 '07
As my Access 2002 form opens, I want to find the names of the tables in the current Access database and populate a combobox with them. Problem is, the CurrentDb.Recordsets object is empty even though I have two tables in the database. I'm using the code below, but the combobox remains empty. That's because CurrentDB.Recordsets is empty. Is this a bug with CurrentDb or have I done something dumb?

Expand|Select|Wrap|Line Numbers
  1. Dim TBL As DAO.Recordset
  2.  
  3. For Each TBL In CurrentDb.Recordsets
  4.     Combobox.RowSource = Combobox.RowSource & TBL.Name & ";"
  5. Next TBL
  6.  

msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#2: Mar 21 '07

re: Access VBA - CurrentDb.Recordsets is empty


Just set the combobox Row Source to this query ...
Expand|Select|Wrap|Line Numbers
  1. SELECT MsysObjects.Name
  2. FROM MsysObjects
  3. WHERE (((MsysObjects.Name) Not Like '~*' And (MsysObjects.Name) Not Like 'MSys*') AND ((MsysObjects.Type)=1))
  4. ORDER BY MsysObjects.Name;
  5.  
Mary
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,219
#3: Mar 21 '07

re: Access VBA - CurrentDb.Recordsets is empty


Quote:

Originally Posted by sphinney

As my Access 2002 form opens, I want to find the names of the tables in the current Access database and populate a combobox with them. Problem is, the CurrentDb.Recordsets object is empty even though I have two tables in the database. I'm using the code below, but the combobox remains empty. That's because CurrentDB.Recordsets is empty. Is this a bug with CurrentDb or have I done something dumb?

Expand|Select|Wrap|Line Numbers
  1. Dim TBL As DAO.Recordset
  2.  
  3. For Each TBL In CurrentDb.Recordsets
  4.     Combobox.RowSource = Combobox.RowSource & TBL.Name & ";"
  5. Next TBL
  6.  

Expand|Select|Wrap|Line Numbers
  1. Dim MyTable As TableDef
  2.  
  3. For Each MyTable In CurrentDb.TableDefs
  4.   'No reason to see the System Tables
  5.   If Left$(MyTable.Name, 4) <> "MSys" Then
  6.      MsgBox MyTable.Name
  7.   End If
  8. Next
Member
 
Join Date: Mar 2007
Location: Columbus, OH
Posts: 69
#4: Mar 22 '07

re: Access VBA - CurrentDb.Recordsets is empty


Thanks!!!!!

Quote:

Originally Posted by ADezii

Expand|Select|Wrap|Line Numbers
  1. Dim MyTable As TableDef
  2.  
  3. For Each MyTable In CurrentDb.TableDefs
  4.   'No reason to see the System Tables
  5.   If Left$(MyTable.Name, 4) <> "MSys" Then
  6.      MsgBox MyTable.Name
  7.   End If
  8. Next

ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,219
#5: Mar 22 '07

re: Access VBA - CurrentDb.Recordsets is empty


Quote:

Originally Posted by sphinney

Thanks!!!!!

No problemo.
Reply


Similar Microsoft Access / VBA bytes