Need help with Delete button (1 Viewer)

  • Thread starter Thread starter Beedrew
  • Start date Start date
B

Beedrew

Guest
Hi Everyone,

I am new to Access. I have a tabular form showing multiple records, and I want to have a delete button on the form to delete the currently selected record. This should be very simple using the Command button wizard, which generates the following on the onClick event of my button:

Private Sub DeleteWizard_Click()
On Error GoTo Err_DeleteWizard_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_DeleteWizard_Click:
Exit Sub

Err_DeleteWizard_Click:
MsgBox Err.Description
Resume Exit_DeleteWizard_Click

End Sub

But when I run the form and click the button to delete a selected record, the record IS deleted but then an error message pops up:

You entered an expression that has an invalid reference to property |.

(Not a typo -- it really looks like the stovepipe in the message).

I have tried replacing the two "DoCmd" lines with the following, which I read was a newer way to activate menu commands:

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

But I get the same error message.

I tried using a macro with the RunCommand / DeleteRecord line, but it works the same way -- deletes the record, but throws an "Action Failed" message that I have to delete.

I got into the debugger a bit by remarking out the error handling in the code above, and it identified the above as run-time error 2455 and flagged the second "DoCmd" line, which actually deletes the record, as the problem (of course!)

I thought of writing a delete query but I did not know how to write one that would not have criteria, but would instead reference the currently selected record in the form.

I am running Access 2002 SP3. Any help would be so very much appreciated, because this simple little task has eaten up hours!

Cheers,

Bee
 
Thanks Wayne (and Cosmos),

I tried that code but it did not work for me; I am getting the same error message as before.

Maybe I'll try moving my database "down" to Access 97, if this is only a problem in newer versions of Access.

Do you (or anyone) know how I could write a Delete query to handle this job, and somehow make it "know" that I want to delete the currently selected record?

Thanks again for the swift response,

Bee
 
Bee,

Is it possible for you to post a sample?

Remove unneeded stuff,
Tools --> Database Utilities --> Compact/Repair
ZIP into a file
Then attach.

Wayne
 
Here's a sample of delete button problem

Hi Wayne,

Just to see if it was some problem with my large database, I created a small database with just one table/query/form and put two delete buttons on the form (all were made using Access wizards). I modified the code of the second delete button to that advised by Cosmos, but I get the same error message no matter what.

These were all created in Access 2002 SP3.

Thanks for any input! I appreciate your time.

Bee
 

Attachments

Bee,

Help, I need more data! I used BOTH buttons on your form and didn't get
ANY errors with either. Now I have no more data.

Did you encounter errors running the db that you sent me? Did you run
it with Access 2003?

I'd do a Tools --> Database Utilities --> Compact/Repair, maybe that'd
help if it was just problems at your end.

I was thinking that your problem might have to do with the fact that
you were using a Tabbed form. Trying to delete data that was being
"updated" on another page.

But, if the simple example database errors, then it sounds like an Access
2003 problem.

What next?

Wayne
 
It's got to be an Access 2002 problem...

Yes, I was getting the SAME error message in both my original database and the sample I posted. I would click the delete button, confirm the delete, and then it would delete the record but then display the same nonsense error message.

But that was in Access 2002 (I do not have 2003)...

I just converted both my original and my sample database from Access 2002 to Access 97 and moved them onto our other computer which has only Access 97. Both databases worked perfectly!

Man, do I EVER wish I had tried converting to Access 97 about seven hours ago...

What version of Access are you using, Wayne? If you say Access 2002 I will not know what to think!!!

Thanks for your help.

Bee
 
Bee,

I'm using Access 2000. I would have thought that using the DoCmd method
would have worked.

It's also interesting to note that the error isn't present just because of the
Tabbed form.

We'll just keep discussing it here, and someone will jump in that might have
seen this before.

Wayne
 

Users who are viewing this thread

Back
Top Bottom