Solved

Method 'Connection of Object' failed

Posted on 2010-11-29
4
1,122 Views
Last Modified: 2013-11-28
I am opening a switchboard in MS Access 2007 which has not changed for a few years but I am now getting an error when the form opens:

Runtime error '-2147418113 (8000ffff)'
Method 'Connection of Object'_CurrentProject'  failed.

The debug line that is a problem is:

 Set con = Application.CurrentProject.Connection

see entire code attached.

Any ideas?
Private Sub FillOptions()
' Fill in the options for this switchboard page.

    ' The number of buttons on the form.
    Const conNumButtons = 8
    
    Dim con As Object
    Dim rs As Object
    Dim stSql As String
    Dim intOption As Integer
    
    ' Set the focus to the first button on the form,
    ' and then hide all of the buttons on the form
    ' but the first.  You can't hide the field with the focus.
    Me![Option1].SetFocus
    For intOption = 2 To conNumButtons
        Me("Option" & intOption).Visible = False
        Me("OptionLabel" & intOption).Visible = False
    Next intOption
    
    ' Open the table of Switchboard Items, and find
    ' the first item for this Switchboard Page.
    Set con = Application.CurrentProject.Connection
    stSql = "SELECT * FROM [Switchboard Items]"
    stSql = stSql & " WHERE [ItemNumber] > 0 AND [SwitchboardID]=" & Me![SwitchboardID]
    stSql = stSql & " ORDER BY [ItemNumber];"
    Set rs = CreateObject("ADODB.Recordset")
    rs.Open stSql, con, 1   ' 1 = adOpenKeyset
    
    ' If there are no options for this Switchboard Page,
    ' display a message.  Otherwise, fill the page with the items.
    If (rs.EOF) Then
        Me![OptionLabel1].Caption = "There are no items for this switchboard page"
    Else
        While (Not (rs.EOF))
            Me("Option" & rs![ItemNumber]).Visible = True
            Me("OptionLabel" & rs![ItemNumber]).Visible = True
            Me("OptionLabel" & rs![ItemNumber]).Caption = rs![ItemText]
            rs.MoveNext
        Wend
    End If

Open in new window

0
Comment
Question by:snailcat
  • 3
4 Comments
 
LVL 84
ID: 34234243
Have you performed maintenance on the database lately? If not:

1) Make a backup.
2) Compact the Database. In Access 2003, click Tools - Database Utilities - Compact. In Access 2007, click the Office Button - Manage - Compact.

If that doesn't work, you might try to Decompile the database. To do that, build a Shortcut with this as the Target:

"full path to msaccess.exe" "full path to your database" /decompile

Now Compact again, then open the VBA Editor and click Debug - Compile. Fix any errors, and continue doing this until the menuitem is disabled. Now compact again.

If that doesn't work, then you might try building a new, blank database and importing everything to that database.
0
 
LVL 12

Author Comment

by:snailcat
ID: 34234572
LSMConsulting--thanks for the ideas.  I had already tried to  compact and repair.
I tried the decomplie/compile without success and also tried importing into a new blank database but this one form is still an issue.

I have older versions of the database that have never been an issue and have not been opened for many months and I am getting the same error for that form in the code described.


Any other thoughts?
0
 
LVL 12

Accepted Solution

by:
snailcat earned 0 total points
ID: 34234781
I repaired my MS Access and the problem is gone.

Thanks for the input.
0
 
LVL 12

Author Closing Comment

by:snailcat
ID: 34272836
Tried expert comments which did not work.  Then did a repair on MS Access on my own and that fixed the problem.
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question