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

Runtime Error 462

Status
Not open for further replies.

waubain

Technical User
Dec 13, 2011
200
US
I am doing screen scraping from Reflections and have typically sent the output to Excel and never had a problem. I am now trying to write to Access. Like many of the other threads, I am getting a runtime error 462 every other time I run this code. In trying to solve the problem, I have commented out all code pertaining to recordsets and basically have left the macro as opening and closing and I still get the error. I must be missing something and not closing all references to Access.

Can anyone see something I am missing? Thank you.

Code:
Sub UpdateTest()

Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim ws As DAO.Workspace

    
    dbPath = "S:\Pharmacy General\Databases Automation\Databases\Test\Test.accdb"
    Set ws = DBEngine.Workspaces(0)
    Set db = ws.OpenDatabase(dbPath)
    Set rs = db.OpenRecordset("tblRPHITemp", dbOpenDynaset)
    
    ....processing code

    rs.Close
    Set rs = Nothing
    db.Close
    Set db = Nothing
    ws.Close
    Set ws = Nothing
    Access.Application.Quit


End Sub

You don't know what you don't know...
 
After some additional reading, I think I have it fixed without really understading how I fixed it. I changed my code to:

Code:
Sub UpdateTest()

Dim objAccess as Access.Application
Dim rs As DAO.Recordset
Dim db As DAO.Database
    
    dbPath = "S:\Pharmacy General\Databases Automation\Databases\Test\Test.accdb"
    Set db = objAccess.DBEngine.OpenDatabase(dbPath)
    Set rs = db.OpenRecordset("tblRPHITemp", dbOpenDynaset)
    
    ....processing code

    objAccess.Quit acQuitSaveAll    
    Set objAccess = Nothing
    Set rs = Nothing
    Set db = Nothing

End Sub

You don't know what you don't know...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top