Link to home
Create AccountLog in
Avatar of jcheath
jcheathFlag for United States of America

asked on

microsoft office access can't open the database because it is missing

When using code to open a access database through Outlook, i get the following error: microsoft office access can't open the database because it is missing.  


Sub PullMembershipUpdate(MyMail As MailItem)

  Dim path As String

  On Error Resume Next 'temporary error handling
  Set objAccess = GetObject(, "Access.Application")

    If Err <> 0 Then 'no existing instances of Access
      Set objAccess = CreateObject("Access.Application")
    End If

    On Error GoTo PullMembershipUpdate_ErrHandler 'normal error handler
    'ShowAccess Instance:=objAccess, Size:=SW_MAXIMIZE
    With objAccess
      path = "M:\Sams_Membership\Database\Blitz2008.mdb"
      If .DBEngine.Workspaces(0).Databases.Count = 0 Then
         .OpenCurrentDatabase FilePath:=path
      ElseIf LCase(Right(.CurrentDb.Name, Len("Blitz2008.mdb"))) _
          <> "Blitz2008.mdb" Then
         .CloseCurrentDatabase
         .OpenCurrentDatabase FilePath:=path
      End If
      .DoCmd.OpenForm FormName:="Update/EMail"
      .Forms("Update/Email").SetFocus
      
      If Date <= "10/17/2008" Then
      .Forms("Update/Email").GoalDate = "10/17/2008"
      Else
      .Forms("Update/Email").GoalDate = Format(Date, "mm/dd/yyyy")
      End If
    End With
    'Access.Forms("Update/Email").Command0
    
    'objAccess.Forms("Update/Email").RunUpdateButton.Click
    Access.Application.DoCmd.RunMacro ("RunUpdate")
    'Access.Application.CurrentDb.Name
    'Call BuildTreoFriendlyFeed
    Access.Application.Run ("BuildTreoFriendlyFeed")
        
Exit Sub

PullMembershipUpdate_ErrHandler:
  MsgBox Error$(), , "Open Database"
End Sub

Open in new window

Avatar of Badotz
Badotz
Flag of United States of America image

Is "M:\Sams_Membership\Database\Blitz2008.mdb" a valid path to the DB?
Avatar of jcheath

ASKER

Yes.  
Where, exactly, does the error occur in your code?

What version of Office? Of Access?

Is the DB an MDB file?
Avatar of jcheath

ASKER

This is where it occurs: On Error GoTo PullMembershipUpdate_ErrHandler 'normal error handler
    'ShowAccess Instance:=objAccess, Size:=SW_MAXIMIZE
    With objAccess
      path = "M:\Sams_Membership\Database\Blitz2008.mdb"

I am using Office 2007 and Access 2003

The DB is in Access so im assuming it is a MDB file.
>>This is where it occurs: On Error GoTo PullMembershipUpdate_ErrHandler 'normal error handler

Does the label PullMembershipUpdate_ErrHandler exist? Otherwise that doesn't sound like the problem.

I asked "where, exactly" and you supplied a comment line plus two code lines, niether of which would account for your "missing" DB error message.

Care to try again?
Avatar of jcheath

ASKER

Well, in that case, i guess im not exactly sure where it occurs.  

I assumed that since the code says:
On Error GoTo PullMembershipUpdate_ErrHandler

and after the Exit Sub it says:
PullMembershipUpdate_ErrHandler:
  MsgBox Error$(), , "Open Database"
End Sub

That that was where the error was coming from. Sorry for the confusion.  But i cant tell excatly where it is coming from.
>>But i cant tell excatly where it is coming from.

Sure you can. Immediately after the Dim path As String statement, add a line with STOP as the command. Now when the function is invoked, the debugger will stop at that line.

Press F8 to step through the code, or F5 to continue with no further interaction.
Avatar of jcheath

ASKER

Okay.  When doing so, it shows an error on:

On Error Resume Next

THis may sound stupid but im assuming the yellow line indicates error?
No, that indicates the line to be executed. When the error occurs, it should goto your handler.
Avatar of jcheath

ASKER

Okay.  Here is where it went to the handler:

.OpenCurrentDatabase FilePath:=path
Then that is where the problen lies.

Either the syntax is incorrect or the FilePath parameter is incorrect (or expecting something else). What does Google say about OpenCurrentDatabase ?
Avatar of jcheath

ASKER

Here is something i've found:

Syntax

application.OpenCurrentDatabase dbname[, exclusive]

Perhaps the pathing is wrong?

Press CTRL-G to open the immediate window, then type in

?path & "<"

and press Enter. That will display the value of path.
Avatar of jcheath

ASKER

This is what came back:

<
So then, path has no value, which would account for your "missing DB" error.

Where in the code are you, looking at your original post?
Avatar of jcheath

ASKER

Im not sure I understand the question.  Can you clarify "where in the code are you"?
Looking at your original code post, what line caused the error?
Avatar of jcheath

ASKER

Here is what caused the error:

If .DBEngine.Workspaces(0).Databases.Count = 0 Then
         .OpenCurrentDatabase FilePath:=path
Move statement
path = "M:\Sams_Membership\Database\Blitz2008.mdb"

Open in new window

before the With..End With loop, re-run the code, and see if that makes a difference.
Avatar of jcheath

ASKER

Same thing/  Once it gets to  .OpenCurrentDatabase FilePath:=path it errors out.  Is there a different way that I should write the path?
ASKER CERTIFIED SOLUTION
Avatar of Badotz
Badotz
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of jcheath

ASKER

Whats intersting is taht i just ran it on another pc and it seems to be working fine.
Not sure how if path is blank?