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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating recordset with VBA problem

Status
Not open for further replies.

cman121

Programmer
Jul 9, 2003
2
US
I am testing this code to solve a larger problem


Private Sub Command0_Click()

Dim rst As Recordset
*** Set rst = CurrentDb.OpenRecordset("tblDepartment")
rst.Index = "PrimaryKey"
rst.AddNew
rst!DepartmentName = "new dept"
rst.Update
'rst.Bookmark = rst.LastModified
rst.MoveNext

End Sub
I get an error on the indicated line (***) that says there is a type mismatch (I assume trying to assign my table to a Recordset ojbect.) Do I need to change my table properties? Why is this a type mismatch?

 
Try changing the dimension statement to the following:

Dim rst As DAO.Recordset
*** Set rst = CurrentDb.OpenRecordset("tblDepartment")

Post back with the results.


Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Looks like you are trying to open a table and not
a recordset, so change the line to the following:

Code:
Set rst = CurrentDb.OpenRecordset("select * from tblDepartment", dbOpenDynaset)

Regards...
 
Chickey, using the table name as the Source is perfectly okay. The Type Constant "dbOpenDynaset" is optional and the absence of which does not trigger the error being found here.

I have tried numerous combinations of code and the only one that triggers the error that is being indicated is if the spelling of the tablename is incorrect or the DAO.Recordset is not used. So, since the tablename is more than likely spelled correctly I belive the addition of the DAO to the recordset declaration will solve the problem.

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top