2
votes

I recently took over a VERY old Access database. This database has a TON of macros written that the users utilize to help them navigate and enter data. Thus, ditching the code is not step #1 despite the fact that these macros were written in Access 97....

I've managed to get most of the code to work by removing deprecated function calls with new ones, but there are a couple of forms that still do not work correctly. If I can figure out how to resolve one I'm sure I can resolve the others.

The main macro has a menu with several buttons. Whenever I click one button I get a "The OpenForm action was cancelled" error. The code for this button is as follows:

Option Compare Database   'Use database order for string comparisons

Private Sub Form_Open(Cancel As Integer)
    If IsLoaded("ServiceCircuit") Then
        Me![PropBtn].Visible = True
    Else
        Me![PropBtn].Visible = False
    End If

End Sub

Private Sub Form_Unload(Cancel As Integer)
    If IsLoaded("ServiceCircuit") Then
        Forms![ServiceCircuit].Visible = True
        Forms![ServiceCircuit]![CircuitPrefix].Requery
        Forms![ServiceCircuit]![CircuitPrefix] = Forms![Circuit]![CircuitPrefix]
        Forms![ServiceCircuit]![CircuitBase].Requery
        Forms![ServiceCircuit]![CircuitBase] = Forms![Circuit]![CircuitBase]
        'Forms!ServiceCircuit.Refresh
        Exit Sub
    Else
        If IsLoaded("DedicatedService") Then
            Forms![DedicatedService].Visible = True
            Forms!DedicatedService.Refresh
            Exit Sub
        End If

        If IsLoaded("Property") Then
            Forms![Property].Visible = True
            Forms!Property.Refresh
            Exit Sub
        End If
    End If
End Sub

Private Sub GRC_GotFocus()
    Me![GRC].Requery

End Sub

Private Sub PropBtn_Click()
    DoCmd.Close

    If IsLoaded("ServiceCircuit") Then
        Forms![ServiceCircuit].Visible = True
        DoCmd.Close
        'Forms![ServiceCircuit]![CircuitPrefix].Requery
        'Forms![ServiceCircuit]![CircuitPrefix] = Forms![Circuit]![CircuitPrefix]
        'Forms![ServiceCircuit]![CircuitBase].Requery
        'Forms![ServiceCircuit]![CircuitBase] = Forms![Circuit]![CircuitBase]
        'Forms!ServiceCircuit.Refresh
        Exit Sub
    Else
        If IsLoaded("DedicatedService") Then
            Forms![DedicatedService].Visible = True
            DoCmd.Close
            'Forms!DedicatedService.Refresh
            Exit Sub
        End If

        If IsLoaded("Property") Then
            Forms![Property].Visible = True
            Forms!Property.Refresh
            Exit Sub
        End If
    End If

End Sub

Private Sub Tariff_NotInList(NewData As String, Response As Integer)
    dumbvar = AddRecFromCombo(NewData, "Tariff")

    '  Continue without displaying default error message.
    Response = DATA_ERRCONTINUE

End Sub

I'm VERY new to VB and have been fumbling my way around it with success but I'm stumped as to how I can tackle this or what the issue could be.

UPDATE:

I set a breakpoint in the main menu form. The code for the actual button is:

Private Sub CircuitBtn_Click()
On Error GoTo Err_CircuitBtn_Click

    Dim DocName As String
    Dim LinkCriteria As String

    DocName = "Circuit"
    DoCmd.OpenForm DocName, , , LinkCriteria

Exit_CircuitBtn_Click:
    Exit Sub

Err_CircuitBtn_Click:
    MsgBox Err.description
    Resume Exit_CircuitBtn_Click

Stepping through the DoCmd.OpenForm DocName, , , LinkCriteria code runs and then it jumps down to Err_CircuitBtn_Click. I do not believe I can set a breakpoint elsewhere. Unsure why this is jumping to the error, the other buttons on the main form are coded the same way (on the main form that is). I tried setting some breakpoints in the first chunk of code (code for the form once it is suppose to pop up) but the breakpoint is never caught. I'm guessing that breakpoint should never be reached as that is the script that is executed if I hit a button ON that form, correct?

4
Can you step through the code using a breakpoint and F8?Fionnuala
I agree - click on first line of event-handler and press F9 to toggle a breakpoint. Then when you run system, you can press F8 to step through code line by line. It will still crash, but at least you'll know where! Post back where this if still stuck.Andy Brown
Sorry, VERY new to VB. Did so, edit coming....WildBill
REM out the On Error statement, so you can see exactly what the error is. Hopefully, it should give you a clue as to what is failingSeanC
REM? Sorry, EXTREME Noob here :/WildBill

4 Answers

1
votes

“OpenForm action was cancelled” is the error you get when the form ("Circuit") doesn't open correctly.

That code was generated by a Wizard, and both "Docname" and "LinkCriteria" are redundant. Try it in the immediate window by entering

`DoCmd.OpenForm "Circuit"`
1
votes

Just experienced the same issue and managed to fixed it.

The problem was that I originally created the form [B] by copying another form [A]. For that reason [B] had the same recordsource (even though it didn't need a recordsource) as [A].

I've renamed the query that was the forms' [A and B] recordsource. I made the update to [A] (the one that needs a recordsource), but didn't realize that [B] also needed an update.

The fix (for me) was to remove the recordsource from [B] since the form did not need to be bound. That said, a fix for others might be to correct the recordsource or other property values that they might have changed in the course of development.

0
votes

I JUST ran into this on access 365. I set the database up for installing at my clients location. This included removing the linked tables so they could be re-linked at the client location on their network.

In testing the accde file it said the OpenForm action was canceled. After scratching my head, I went back to the file that the accde was made from. I got the same issue. I thought it may have been my custom ribbon, but no.

I then decompiled that file's VBA in a hope that I would get an answer, no. I then eliminated the ribbon all together and tried to open the form directly. It said the Record Source did not exist. I was like, "Oh yes it does, I am looking right at it."

I then tried to open the record source (A query in this case), and it said it couldn't find a table.

OH OF COURSE. I removed all the links to the data tables.

-1
votes

I guess you don't need the answer anymore (It's been a while since you asked it), but I write a solution for others:

On Error GoTo ErrorHandler

' Insert code that might generate an error here

DoCmd.OpenQuery "query_name"

Exit Sub

ErrorHandler:

' Insert code to handle the error here

MsgBox "The query did not run"

Resume Next