Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create empty DAO.Recordset 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I seem to be stuck creating an empty DAO recordset so I can add records to it on the fly and use it to create an XLS file.

I have..
Code:
Private Sub Class_Initialize()

    Dim tbl As DAO.TableDef
    
    'define current database
    Set db = CurrentDb()
    
    'create table
    Set tbl = db.CreateTableDef
        
    'create fields for table
    With tbl
        .Fields.Append .CreateField("Field 1", dbText)
        .Fields.Append .CreateField("Field 2", dbText)
        .Fields.Append .CreateField("Field 3", dbInteger)
    End With
        
    ' create recordset for the blank table
    Set rsProcess = tbl.OpenRecordset
    
    rsProcess.AddNew
    rsProcess("Field 1").value = "test"
    rsProcess.Update
            
End Sub

It compiles without error, but when I try to use the class, I get 'object invalid or no longer set' error , which points to
Code:
    Set rsProcess = tbl.OpenRecordset

What am I doing wrong?

Thanks,
1DMF.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Your table must have a name and be appended to the TableDefs collection.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV -> Does that actually create a physical table in the DB application?

MajP -> Probably , but that uses ADO and my whole application is based on DAO!

Might I just as well create an empty table for polulating, it's easier and doesn't require ADO?

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Does that actually create a physical table in the DB application
Yes.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Like I thought, then I might as well just create a blank table for the purposes of filling with the export records and do a simple transferspreadhsheet against it.

Thanks PHV.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top