tags:

views:

14

answers:

1

I'm using a Switchboard Database to run macros on multiple Access databases one after the other using the code below. Running the "Updata Data" macro in Data1.accdb requires logging on to a SQL Server. If a user enters an incorrect password the code freezes. Any suggestions for how to gracefully handle an incorrect log-on attempt?

Set objACC = GetObject("\Data Tables\Data1.accdb") 
objACC.DoCmd.RunMacro ("Update Data") 'run macro
objACC.Quit

Edit: It looks like the problem is not an incorrect login. I know the macro works when fired from the "Data1.accdb" database but when I kill it on a freeze up there is a message about "not being able to create an Active X component". I'll do more research and ask a more coherent question when I have more info. In the mean time I will call the "Use Error Handling" answer correct because that does let me know when the password is incorrect.

A: 

Something like:

On Error GoTo Error_LogonError

    Dim db_path As String
    db_path = "\Data Tables\Data1.accdb"
    Set objACC = GetObject(db_path) 
    objACC.DoCmd.RunMacro ("Update Data") ''#run macro
    objACC.Quit

Error_LogonError:
    Debug.Print "hi, there was an error logging on to " & db_path
Adam Bernier