UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Error Handling, Access 2010    
 
   
bakersburg9
post Dec 28 2017, 05:35 PM
Post#1



Posts: 5,100
Joined: 2-November 04
From: Downey, CA


I have a form with a button to exit (quit) my database after dropping a table - but if the database is opened later, and the table hasn't been re-instated - there will be an error that the table does not exist - is there a way I can deal with this through error handling ? I wouldn't know where to begin....
CODE
cmdExitDatabase_Click()

DoCmd.SetWarnings False  ' Don't want error if table doesn't exist

'Delete 'Invoice Approvals' table - when data is exported from Sharepoint, want it to go in a table named "Invoice Approvals"
MsgBox "Warning! 'Invoice Approvals' table will be deleted upon exit - if you are finished, that's ok", vbYesNoCancel

DoCmd.DeleteObject acTable, "Invoice Approvals"

DoCmd.Quit

DoCmd.SetWarnings True


Any help would be greatly appreciated....
Go to the top of the page
 
RJD
post Dec 28 2017, 06:15 PM
Post#2


UtterAccess VIP
Posts: 8,221
Joined: 25-October 10
From: Gulf South USA


Hi: Rather than use error handling for this, you could include UA's own TableExists function from the Wiki and apply it like this ...

Public Function DeleteTable()

If TableExists("Invoice Approval") Then

DoCmd.DeleteObject acTable, "Invoice Approval"

End If

End Function

...adding back the other code items you are using as well ...

I would also suggest (although it does not affect this solution) that you eliminate the space from the object name ... just saying ...

HTH
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
bakersburg9
post Dec 28 2017, 07:13 PM
Post#3



Posts: 5,100
Joined: 2-November 04
From: Downey, CA


Great idea ! How do I set up the TableExists function ? it says function not defined - as for the spaces, yeah, it just comes out that way, and the cost/ben. doesn't work out to take out the space, because someone else is going to be administering this db
Go to the top of the page
 
RJD
post Dec 28 2017, 07:34 PM
Post#4


UtterAccess VIP
Posts: 8,221
Joined: 25-October 10
From: Gulf South USA


Hi again: you can copy the function from the Function library here at UA and put it in a standard module. I have that already done, but am not in my office right now.

I'll check back when in my home office and see if I need to post the demo for you.

HTH
Joe

from phone

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
bakersburg9
post Dec 28 2017, 08:18 PM
Post#5



Posts: 5,100
Joined: 2-November 04
From: Downey, CA


Hey, thanks, Joe !! cool.gif
Go to the top of the page
 
RJD
post Dec 28 2017, 11:48 PM
Post#6


UtterAccess VIP
Posts: 8,221
Joined: 25-October 10
From: Gulf South USA


You didn't say if you needed it, but here's my demo that includes the TableExists function just in case ...

HTH
Joe
Attached File(s)
Attached File  CheckTable.zip ( 20.32K )Number of downloads: 4
 

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
bakersburg9
post Jan 4 2018, 12:37 PM
Post#7



Posts: 5,100
Joined: 2-November 04
From: Downey, CA


Joe,
Thanks so much for that !!!! Works GREAT !!! I knew I'd get there .... cool.gif

Steve
Go to the top of the page
 
RJD
post Jan 4 2018, 04:42 PM
Post#8


UtterAccess VIP
Posts: 8,221
Joined: 25-October 10
From: Gulf South USA


You are very welcome, Steve. Happy to assist.

Regards
Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 
bakersburg9
post Jan 4 2018, 05:50 PM
Post#9



Posts: 5,100
Joined: 2-November 04
From: Downey, CA


I spoke too soon - now it's erring - all I did was change two of the module names - now I'm getting an error:
QUOTE
The expression you entered has a function name that Microsoft Access Can't Find
What??? Why would it err just because I changed the module names ?

See attached db - I have it set up for a form (the only form) to open on Startup - when I click the "Exit Database" button, there's code behind the button to run the DeleteTable() function, which calls the TableExists function you shared with me - it's supposed to DROP the "Invoice Approvals" table if that table exists - not send me a Nastygram :-( grrr... I've attached the db, if you want to look....


EDIT:
Found this: "Note: You can't call a Function procedure from a macro if the function name is the same as the module name.

... well, butter my butt and call me toast.... WHO KNEW ???? - Never mind.....
This post has been edited by bakersburg9: Jan 4 2018, 06:26 PM
Attached File(s)
Attached File  Invoice_Approvals.zip ( 58.06K )Number of downloads: 1
 
Go to the top of the page
 
RJD
post Jan 4 2018, 07:14 PM
Post#10


UtterAccess VIP
Posts: 8,221
Joined: 25-October 10
From: Gulf South USA


Hi Steve: Glad you got that sorted out! Right, it's a naming issue ...

Joe

--------------------
"Each problem that I solved became a rule, which served afterwards to solve other problems."
"You just keep pushing. You just keep pushing. I made every mistake that could be made. But I just kept pushing."

Rene Descartes 1596-1650 (Mathematician and Philosopher)
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    19th April 2018 - 06:48 AM