Open another database with a button

jsbarroso

Registered User.
Local time
Today, 13:16
Joined
May 3, 2013
Messages
49
I am using the following event code to open a database from another. Everything works fine but, I would like add a mxgbox letting the user know the database does not exists and to contact me for assistance. Any ideas?


Private Sub cmdOpenTime_Click()
Dim accapp As Access.Application

Set accapp = New Access.Application
accapp.OpenCurrentDatabase ("c:\PILOT_Application\TIME.Accdb")
accapp.Visible = True
End Sub


Thank you in advance
 
look up the Access function Dir

update: as Plan B, google Access error handling
 
Use the On Error command. First simulate the case where the database does not exist so that you can write down the error number then try this out:

Code:
Private Sub cmdOpenTime_Click()
Dim accapp As Access.Application
Set accapp = New Access.Application

On Error GoTo ErrorHandler:
accapp.OpenCurrentDatabase ("c:\PILOT_Application\TIME.Accdb")
accapp.Visible = True

ErrorHandler:
If Err.Number = <error number> Then
    Msgbox "database does not exist, contact dev."
Else: GoTo GenericErrorMessage:
End If

GenericErrorMessage:

Msgbox "An error occured, contact dev."


End Sub
 
Beansy, Thank you for your post. When I run the code I get a "Compile Error: Syntax error" message on the line

If Err.Number = <error number> Then
 
Beansy, Thank you for your post. When I run the code I get a "Compile Error: Syntax error" message on the line

If Err.Number = <error number> Then

you need to replace <error number> with the error number. (Without the inverted brackets)
 
I knew that... It has been one of those nights. Thank you again.
 

Users who are viewing this thread

Back
Top Bottom