Object doesn't contain Automation object

2wistd

Registered User.
Local time
Yesterday, 19:25
Joined
Jan 17, 2013
Messages
66
So my program worked just fine, now i create a switchboard and try to run the Module, now I get the error "The object doesn't contain the Automation object 'deleteoldrecords'.

The code for it is:
Code:
Public Function deleteoldrecords()
LResponse = MsgBox("Do you want to delete Graduated Students?", vbYesNo, "Continue")
If LResponse = vbYes Then
    DoCmd.SetWarnings False
    DoCmd.RunSQL "Delete * from GradStudentsQuery"
    MsgBox "Successfully Deleted Graduated Students", vbOKOnly
Else
End If
End Function

It shows up under 'Unrelated Objects'.

I hope it is something simple, thanks in advance.
 
Where is your function located? Is it in a Module, in the Startup Form? It can not be in another form.

http://www.blueclaw-db.com/docmd_runsql_example.htm
Example of deleting * from the NorthWind DB above

This worked for me. If you go to your query in the record view, can you highlight a record and delete it?
Just wondering if your GradStudentsQuery has some one-to-many relationship that prevents a record from being deleted. For example - a calculated field, a Totals, or some other condition. If you can't manually highlight a record in the query and delete it manually, the code won't be able to delete records either.

Code:
Public Function deleteoldrecords()
Dim LResponse As Integer
LResponse = MsgBox("Do you want to delete Graduated Students?", vbYesNo, "Continue")
If LResponse = vbYes Then
    DoCmd.SetWarnings False
    DoCmd.RunSQL "Delete * from GradStudentsQuery"
    MsgBox "Successfully Deleted Graduated Students", vbOKOnly
    DoCmd.SetWarnings True
    
Else
End If
End Function

One more tip: if the function is not going to return something, why not make it into a Sub? Suggest that you modify it to:
Public Function deleteoldrecords() as Boolean
Once you verify the Delete query ran with out an error, then return True for the Function.

By The Way - I always wondered what happened to Graduated Students LOL
 
Last edited:
Oh my, each time I feel that I am getting a grasp of access, there is more to learn. I can delete a record from the query without a problem.

I'm going to have to read that link and hopefully find the issue.

This is for a database to keep instructors, new students and returning students organized. We have new students and graduations pretty much every week. So being able to run the function would be handy.

Thanks!
 
DO NOT EVER do THIS:
DoCmd.SetWarnings False without subsequently doing this:
DoCmd.SetWarnings True

because you are depriving yourself from the system messages after the first run.Your error message shows that Access cannot find the code you wish it to run. Wat is the name of the module? NOt the same as your function, I hope?
 
"NOt the same as your function, I hope? "

You hoped wrong, the module and function had the same name :banghead:

Thanks! This board has been great so far!
 

Users who are viewing this thread

Back
Top Bottom