Delete table in code ACC2003

User avatar
Michael Abrams
4StarLounger
Posts: 574
Joined: 10 Feb 2010, 17:32

Delete table in code ACC2003

Post by Michael Abrams »

I am sorry to bother you all with something that should be so simple, but i cannot figure out what i am doing wrong.

Here is the code:

Code: Select all

'Print the records in the tables
DoCmd.OpenTable "PA-ACT-HEADERS-TRAILERS", acViewNormal, acEdit
    DoCmd.PrintOut acPrintAll, , , acHigh, 1, True
    DoCmd.Close acTable, "PA-ACT-HEADERS-TRAILERS"
    
DoCmd.OpenTable "PA-ELIG-HEADERS-TRAILERS", acViewNormal, acEdit
    DoCmd.PrintOut acPrintAll, , , acHigh, 1, True
    DoCmd.Close acTable, "PA-ACT-HEADERS-TRAILERS"
    
'DELETE THE TABLES
DoCmd.DeleteObject acTable, "PA-ACT-HEADERS-TRAILERS"
DoCmd.DeleteObject acTable, "PA-ELIG-HEADERS-TRAILERS"<------------------
This works fine: DoCmd.DeleteObject acTable, "PA-ACT-HEADERS-TRAILERS"

The next line receives this: Error Message 2208: You cannot delete the database object PA-ELIG-HEADERS-TRAILERS while it's open.

Doesn't this line close the table? DoCmd.Close acTable, "PA-ACT-HEADERS-TRAILERS"

I appreciate your help as always.

Thank you.
Michael

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Delete table in code ACC2003

Post by HansV »

Perhaps the printing action isn't completely finished yet when you get to the offending line. You could insert one or two lines with

DoEvents

between the printing and deleting, or if that doesn't help, show a message box:

MsgBox "Click OK when printing is finished.", vbInformation
Best wishes,
Hans

User avatar
Michael Abrams
4StarLounger
Posts: 574
Joined: 10 Feb 2010, 17:32

Re: Delete table in code ACC2003

Post by Michael Abrams »

I tried both.
DoEvents didn't work.

Messagebox didn't work. I actually waited for the printing to stop, went to the printer, came back & clicked OK and same error message.

When I commented out the delete code and create a small form with the delete code, it works fine.

Michael

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Delete table in code ACC2003

Post by HansV »

That's weird!
Best wishes,
Hans

User avatar
Michael Abrams
4StarLounger
Posts: 574
Joined: 10 Feb 2010, 17:32

Re: Delete table in code ACC2003

Post by Michael Abrams »

HansV wrote:That's weird!
No.... I am weird.... or actually I am sorry for wasting your time.

Code: Select all

DoCmd.OpenTable "PA-ELIG-HEADERS-TRAILERS", acViewNormal, acEdit
    DoCmd.PrintOut acPrintAll, , , acHigh, 1, True
    DoCmd.Close acTable, "PA-ACT-HEADERS-TRAILERS" <-------------
It would help if I tried to close the table that I opened ...... :blush:

Naturally it works fine now.

Oy.

Thank you Hans - At least I have a 4 day weekend coming up, thank goodness.

Michael

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Delete table in code ACC2003

Post by HansV »

Ack - I should have seen that! Sorry.
Best wishes,
Hans