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

If object exist question

Status
Not open for further replies.

sibleytr

Technical User
Jan 27, 2005
21
US
Whenever the FE of my MDB loads it asks for a project to manage. Depending on the project, and it's location, it will delete the existing link and then connect to the needed BE link table.

However I have a situtaion where sometimes the linked table is not present to delete and thus the code fails.

Code:
    DoCmd.DeleteObject acTable, "tblock"
    DoCmd.TransferDatabase acLink, "Microsoft Access", strProjectPath.Value & "\DGNData.Mdb", acTable, "tblock", "tblock"

Is there away to create a If Then Else statement to check to make sure the object exist?

Code:
if exist <<linkTable>> then delete
Else
<<linkNewTable>

 
What's often used, is just to allow for the exception, and go on:

[tt]on error resume next
DoCmd.DeleteObject acTable, "tblock"
if err.number<>0 then
err.clear
' it didn't exist
end if
on error goto <your error handler>
DoCmd.TransferDatabase acLink, "Microsoft Access", strProjectPath.Value & "\DGNData.Mdb", acTable, "tblock", "tblock"[/tt]

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top