Link to home
Start Free TrialLog in
Avatar of Ted Palmer
Ted PalmerFlag for United States of America

asked on

Access 2007 run in Debug mode

EE Experts,

This seems like a stupid question but I have to ask it any way. How do I get my application in MS-Access 2007 to run in debug mode? When I am in the code editor and set a break point; I press F5 to execute in Debug or click on the right pointing green arrow head, and a dialog box pops up asking me to enter the name of a macro that I want to run. I don't want to run a macro. I want to execute my application till it hits the breakpoint I set.
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Once you hit a break point, use F8 to single step through the code from the break point.

mx
You may mean safe mode:
Hold Ctrl while opening Access
F5 ... see image.  If say you put the cursor over (click) a Function name or double click to highlight the name ... then hit F5 ... that will execute the Function ... and in this case, the breakpoint will stop the execution.

mx
Capture1.gif
OOPs ... wrong image ... (same as first) ... see THIS one:

mx
Capture2.gif
Hi,

> I want to execute my application till it hits the breakpoint I set.
You don't need to set a "Debug" mode at all.  Just set the breakpoint in VBE, then when the application runs as normal and hits the breakpoint, it will stop.  Access is forever in "debug"-able mode.
Avatar of Ted Palmer

ASKER

mx,

I should have had this ready. See image of dialog box I get when I follow your instructions.
MacroName.bmp
When I click the Debug menu drop down menu F8 Single Step, nothing happens.

Ted Palmer
mx,

I saw your posts. Yes!
"When I click the Debug menu drop down menu F8 Single Step, nothing happens."

Is your code stopped at a break point ?

mx

Private Sub btnRun_Click()
    If gcfHandleErrors Then
        On Error GoTo Err_Handler
        Err.Clear
    End If
    
    Dim OKToReport As Boolean
    
    OKToReport = True
    
    If IsNull([Beginning Date]) Or IsNull([Ending Date]) Then
        MsgBox "You must enter both beginning and ending dates.", vbInformation, "AutoSubrogate(TM)"
        'DoCmd.GoToControl "Beginning Date"
        OKToReport = False
    Else
        If [Beginning Date] > [Ending Date] Then
            MsgBox "Ending date must be greater than Beginning date.", vbInformation, "AutoSubrogate(TM)"
            'DoCmd.GoToControl "Beginning Date"
        OKToReport = False
        Else
            OKToReport = True
        End If
    End If
    Select Case Me.optnframeClients
        Case 1     'forwarder companies
           DoCmd.OpenReport "rptClientFiles1", acViewReport, OpenArgs:="qryClientForwarderCoFiles"
        Case 2    'insurance companies
           DoCmd.OpenReport "rptClientFiles1", acViewReport, OpenArgs:="qryClientInsuranceCoFiles"
        Case Else
           MsgBox "select Option", vbInformation, "AutoSubrogate(TM)"
           Exit Sub
    End Select
    
    If OKToReport Then
        Me.Visible = False
    Else
        DoCmd.GoToControl "Beginning Date"
    End If

Exit_Sub:
    Exit Sub

Err_Handler:
    Select Case Err.Number
        Case 11
            MsgBox "A division by zero error was thrown in screen form class frmMyFilesByClient >> Subroutine btnRun_Click. " _
            & "Error number: " & Err.Number & " Error Description follows: " & Err.Description, "AutoSubrogate(TM)", vbCritical
            Resume Exit_Sub
        Case 32000 'User defined error numbers begin at 32000 go to 65535. Use "Err.Raise 32000" in code to trigger error.
            MsgBox "A User Defined error was thrown in screen form class frmMyFilesByClient >> Subroutine btnRun_Click. " _
            & "Error number: " & Err.Number & " Error Description follows: " & Err.Description, "AutoSubrogate(TM)", vbCritical
            Resume Exit_Sub
        Case Else
            MsgBox "A General Exception was thrown in screen form class frmMyFilesByClient >> Subroutine btnRun_Click. " _
            & "Error number: " & Err.Number & " Error Description follows: " & Err.Description, "AutoSubrogate(TM)", vbCritical
            Resume Exit_Sub
        End Select
End Sub 'btnRun_Click()

Open in new window

Cyberkiwi,

My break point is on line # 11

I run my app from the main menu and it blows right on by the break point.

mx,

My code is not stopping at the break point.

TedPalmer
All,

This has been happening this way before I added all the "On Error GoTo Err_Handler' stuff.

TedPalmer
OK ... F5 only works in standard modules, not in code behind controls on forms ... I think.

So ... you would need to set a break point ... then click the button ... code stops at breakpoint, then you use F8 to single step through.

mx
Also ... put the break point right on the Sub name ... and go from there.  IF ... no stop, then the code has become disconnected from the button - usually due to a name change on the button.

mx
Public Const gcfHandleErrors As Boolean = False
mx,

I don't believe the code is disconnected from the button, but I don't deny the possibility of that. I can tell by the way the code behaves. I get the error message that you see in the code.

TedPalmer
> I run my app from the main menu and it blows right on by the break point.

Do you mean it goes right past it?

Put the cursor on the line just after the sub header, as DbMX has suggested, and hit F5.

Private Sub btnRun_Click()

The hit F8,F8,F8 to watch it step through.
can you upload the mdb ... with exact description how to reproduce ... ?

C&R and Zip ....

mx
mx,

Also I am sure the name of the button has not changed for a very long time. It has been running OK this way for a long time.

Thank you,

TedPalmer
"Put the cursor on the line just after the sub header, as DbMX has suggested, and hit F5."

But F5 doesn't work inside of a sub on a form control.

mx
I don't believe up loading the ACCDB file would help. all tables are linked. The data wouldn't be there.

TedPalmer
Time for some old school debugging...

!! ACHTUNG !!
Make a backup of the database, and you may have to kill Access to get by the messages when you do it this way.
Once you figure out the problem, use the backup of the database instead of continuing with the file if you have ever had to kill Access via Task Manager.

Let's start with 2 simple message boxes, to verify that we can get the code running.
Private Sub btnRun_Click()
    If gcfHandleErrors Then
MsgBox "Setting error handler"
        On Error GoTo Err_Handler
        Err.Clear
    End If
    
    Dim OKToReport As Boolean
    
    OKToReport = True
MsgBox "Just before Null tests"
    
    If IsNull([Beginning Date]) Or IsNull([Ending Date]) Then
        MsgBox "You must enter both beginning and ending dates.", vbInformation, "AutoSubrogate(TM)"
        'DoCmd.GoToControl "Beginning Date"
        OKToReport = False
    Else
        If [Beginning Date] > [Ending Date] Then
            MsgBox "Ending date must be greater than Beginning date.", vbInformation, "AutoSubrogate(TM)"
            'DoCmd.GoToControl "Beginning Date"
        OKToReport = False
        Else
            OKToReport = True
        End If
    End If
    Select Case Me.optnframeClients
        Case 1     'forwarder companies
           DoCmd.OpenReport "rptClientFiles1", acViewReport, OpenArgs:="qryClientForwarderCoFiles"
        Case 2    'insurance companies
           DoCmd.OpenReport "rptClientFiles1", acViewReport, OpenArgs:="qryClientInsuranceCoFiles"
        Case Else
           MsgBox "select Option", vbInformation, "AutoSubrogate(TM)"
           Exit Sub
    End Select
    
    If OKToReport Then
        Me.Visible = False
    Else
        DoCmd.GoToControl "Beginning Date"
    End If

Exit_Sub:
    Exit Sub

Err_Handler:
    Select Case Err.Number
        Case 11
            MsgBox "A division by zero error was thrown in screen form class frmMyFilesByClient >> Subroutine btnRun_Click. " _
            & "Error number: " & Err.Number & " Error Description follows: " & Err.Description, "AutoSubrogate(TM)", vbCritical
            Resume Exit_Sub
        Case 32000 'User defined error numbers begin at 32000 go to 65535. Use "Err.Raise 32000" in code to trigger error.
            MsgBox "A User Defined error was thrown in screen form class frmMyFilesByClient >> Subroutine btnRun_Click. " _
            & "Error number: " & Err.Number & " Error Description follows: " & Err.Description, "AutoSubrogate(TM)", vbCritical
            Resume Exit_Sub
        Case Else
            MsgBox "A General Exception was thrown in screen form class frmMyFilesByClient >> Subroutine btnRun_Click. " _
            & "Error number: " & Err.Number & " Error Description follows: " & Err.Description, "AutoSubrogate(TM)", vbCritical
            Resume Exit_Sub
        End Select
End Sub 'btnRun_Click()

Open in new window

cyberkiwi,

I believe I have the code running because I get the MsgBox on line # 14. in the code snippet you uploaded.
TedPalmer:

Put a break point on the Sub name, then click your command button.

mx
mx and cyberkiwi,

I should have begun this conversation earlier. I have to go to a computer club meeting. I should have known that it wasn't going to be easy. From talking with you guys, I at least know that I have been doing the right thing.

Thank you for your help.

I'll be back in about 3 hours.

Oh! I forgot to respond. . . . Yes I have killed Access from Task Manager before.

Ted Palmer
Two screen shots.
MyBreakPoints.bmp
2nd screen shot. MsgBox
MsgBox-01.bmp
So ... sorry, but I'm lost now.  What is the remain issue ?

mx
mx,

My understanding is that even though it runs and the message prompt appears, it just never stops at the breakpoint.
Hi Ted,

I would still be interested to see you try the code in http:#a33158465
That is to be 100% certain that the procedure you are putting the breakpoints in is actually what it is running!
There might be something similar tucked away behind another form or module...

Just a thought.
Anytime I have odd VBA-related errors I think of corruption. Have you tried:

*** Make a backup first ***

1) Compact - click the Office button - Manage - Compact
2) Compile the Code - from the VBA Editor, click Debug - Compile. Fix any errors, and continue until the menuitem is disabled
3) Compact again.

Now try a Decompile: Build a shortcut with a target like this:

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

Now do the 3 steps again

Whether this works or not: Build a new, blank database and import everything into that new database.

All,

I received some more good ideas to try while I was gone at my meeting. I can't give up now. You guys have too much invested in my success for me to do that. I'm not going to try these this evening when I'm tired. I don't want to make a mistake in implementing any of your ideas, then say in error something didn't work. So I'll get right back on this first thing in the morning.

Thank you all for your patience and help.

Ted Palmer
So, What is the remaining issue ?

mx
A couple of comments that might help:
1. If you get the macro dialog shown here http:#33158229 when hitting F5, it means code execution has already been stopped.  You need to re-execute your program.  VBA code is either in a "running state" or a "stopped state".  There is no special "debug" mode as has been said.
2. <<My break point is on line # 11. I run my app from the main menu and it blows right on by the break point.>>
  Usually, that means simply that the code in question is not getting executed as you think it should be.  With controls, what often happens is that you'll change the name of a control and when you do,  the code does not go with it.  You need to go back to the property sheet, change the event to "[Event Procedure]" and then copy the code into the event.   I've also found on occasion that the "[Event Procedure]" in the property sheet simply gets cleared.   So any time code doesn't execute (you don't hit your break point), first verify that it is being called.   If that all checks out, then it might mean that the VBA file is corrupt.
  As for setting breakpoints, rather then using one I often use STOP instead.  The VBA IDE has some issues with clearing break points, so I often use a stop, which can be taken out while the code is executing once you've hit it.  All you need to do is step past it (with F8), then edit out the line and save.
  So what I do is sprinkle stops throughout a process and then as I hit each one, I take them out as needed as I check each section of a process.
The other thing I do in apps is use a procedure  DebugMode(), which checks a flag as to whether or not I consider my application to be in "debugging mode".  Then in the code, I will do something like this:
  If Not DebugMode() then
     Application.Quit
  End If
  I use this to avoid things I don't want to do as a developer (like quite the app when I hit the exit button) that a normal user would.   However it is not good for debugging code like your doing here, but I thought it was worth mentioning as it comes in handy at times.    And note this has nothing to do with VBA itself, but something I am doing within VBA.
3. <<OK ... F5 only works in standard modules, not in code behind controls on forms ... I think.>>
  All the debugging options in the VBA IDE work the same whether it's a form module, class module, or standard module.  The only thing that is different is when your in a stopped state.  You can't start code execution in a form , report, or class module with F5 as they are all classes and need to be instantiated (an instance created as an object).  I think that's what MX meant, but I wasn't sure from reading the thread.
  all of this is just some finer points on what's already been said, so no points here please.
JimD.
 
All,

I'm working on this. Taking into consideration all comments.

mx,

The remaining issue for me now is the same as I started with. The execution of the VBA code does not stop at the break point.

I put some "tracer" characters in my MsgBox to verify which code I am running. Saved my changes. Tried to resume execution of my app from where I was. It just locked up and had to be killed using Windows Task Manager. I know from a recent bad experience with the VS2008 IDE that causes problems that require special effort to recover from. Some things do not get saved when I do that. This is at least the 2nd time I have done that since I started making this special effort to be able to set break points and get the execution of the VBA to stop on the break point. I have never been able to do that with this application, and I don't recall how far back that goes but it could be as long as a year ago. This is the only application I have in MS-Access 2007. So for me it seems that in MS-Access 2007 debug does not work. I now know that is not true.

I have several suggestions to work with here. This time I am going to make this work because I have a stronger need for use of the debugger and it is just something that I should always have.

Thank you all.

Ted Palmer
This is the first of 3 screen shot that I will upload then comment on what they mean to me.

Ted Palmer
MsgBox-With-Tracer-Chars.bmp
Second Screen Shot. One more on the way.
NoData4ThisReport.bmp
This is a screen shot of source code that has breakpoint and MsgBox with the tracer characters in them. You can see from the previous screen shot that this I hope proves to me that I am executing the source code that has the break point.

More to follow.

Thanks,
Ted Palmer
-beginning-.bmp
So ... what you saying is per the last screen shot is ... the code executes right through the break point and then the message box pops up, right?  

And what happens if you put the break point right on

Private Sub btnRun_Click()

?

IF ... it does not stop at any of these places, then I would do what LSM suggested @http:#a33158762

mx
Ted,
I think you have proven beyond reasonable doubt that the breakpoint is where you need it to be and that sub is the one that is running.
At this point, I would concur with LSM, rebuild/repair the access db, or rebuild access itself!

For what it's worth, try the mdb on another machine and see if it works (flush out access problems).
For what it's worth, try another mdb on that machine and see if it works (flush out problems with the mdb).
All,

I am not there yet but I have made some progress. The "tracer" characters are the '&' and '+' that delimit the word beginning. You can see from the screen shot in comment 33164177 that I am executing the source code with the breakpoint in it. The execution had to pass through the IF statement testing for the null values to display that MsgBox.

I followed the instructions given by LSMC in http:#33158762 except for the last one. I hope I can get by without that because there would be a BIG bunch to import. I believe this is what fixed what I messed up by killing my application using Windows Task Manager 2 times.

I am executing my application from the very beginning at the Main Menu Switchboard after I set the breakpoint in the Subroutine I am working on. As best I can tell the execution passes right through the breakpoint and executes the MsgBox with the "trace" characters. So I still have my original problem.

I am about to print and follow the instructions given by JimD in http:#33161126. I post the results of that after I have them.

Part of my problem is that MS-Access is only my secondary language skill set. My primary is VB.NET from the VS2008 IDE. So that sets my expectations of how the IDE in MS-Access 2007 should behave, and that is a mistake. I think MS-Access was originally written in India because of the Switchboard metaphor. But that is stuff for a whole magazine article that doesn't belong here.

More to come.

Thank you all.
Ted Palmer
@JD " I think that's what MX meant, but I wasn't sure from reading the thread."
Exactly.  So, the debugging options do quite work the same everywhere.

"I think MS-Access was originally written in India because of the Switchboard metaphor. "
No.  Not the case.  Redmond.

"I am executing my application from the very beginning at the Main Menu Switchboard"
Can you just open the form in design view, get to the code window, then set the break point, open the form and click  the btnRun button ... and see what happens ?

mx
mx,

I'll try moving the breakpoint per your suggestion to Private Sub btnRun_Click() to see what happens first.

Thanks,
Ted Palmer
mx,

I tried as you requested, and I am still getting the same results.

Ted Palmer
MyFilesByClientBtnRun.bmp
All,

Sometimes what I think should make no difference makes a difference. So even though I think this shouldn't be necessary, here it is. The screen form I am working from.

Ted Palmer
MyFilesByClient.bmp
"and I am still getting the same results."
So ... code does *not* stop at breakpoints, but message boxes appear, right ?

ok ... and you tried the Decompile per LSM (skipping the Import), right ?

mx

mx,

I just saw your comment http:#33164391 I'll try that now. Thanks.

Ted Palmer
mx,

I tried it by just "opening" the form directly from the Access Designer view I think it is called. I got the same results.

Other topic. Maybe it was programmers from India working in Redmond. I understand that there are a lot of them there too. The Switchboard metaphor is just so foreign. Access is does not "look and feel" like software that came from Microsoft.

Thanks for your help and patience.

Ted Palmer
"Other topic. Maybe it was programmers from India working in Redmond."
I don't think so ... back circa early 90's, the India thing was not really happening then.  Sorry.

Access is one of the all time best products to come out of Microsoft. When you really know the full capabilities as I do ... it's truly amazing.

Anyway, at this point ... assuming you've tried all the things above, short of Uninstalling and re-installing Office (as much as I HATE to suggest that - or at least try Office Repair first) ... I'm out of ideas.  If you want to upload, I can check it out tonight on my A2010 system.

mx
ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mx and LSMC,

Not posted for a while because I have been reading and doing some minor experiments, I copied the offending accDB file to another PC where I have MS-Access 2007 and it behaves the same way. I should have tried it on a copy of Northwind for 2007 that I have somewhere by now but I have been reading. I may end up trying the import thing, but copying my whole accDB file to a publicly accessable website just goes against my religion. All my tables are linked to a MySQL database. MySQL has a database adapter modeled after ADO.NET.

Other topic: I'm sure you are right about Access' capabilities. My main application client is in VB.NET 2008, but I decided to use Access for the reports module because I knew that I could get a lot more value and quantity in reports in less time using Access with an ODBC data adapter to MySQL. I just have to struggle a lot because I don't use it constantly enough to be real familiar with its idiosynchrocies.

I'm still on this. That is another one of my many character flaws. I seldom take the easy way, I don't give up easy, and that costs me dearly in time, but I learn a lot along the way. I expect to have this resolved by the end of the day tomorrow.

Thank you all for your time effort and patience.

Ted Palmer

All,

Update: I finally found one of my copies of "Northwind 2007.accdb" file. I was able to put a breakpoint in the "Ship" button click procedure on the order details form. When I ran the application and clicked the "Ship" button execution stopped on the subroutnie label and high lited it in yellow like I would expect. So therefore the problem is not in the installed instance of MS-Access 2007. And it was so easy, it is hard to see how I could be doing anything wrong in my AutoSubrogate report module. So that is where the problem has to be.

The thought just occured to me. I think I started this whole application by cloning from a MS-Access 97 application because a few years ago I was bored at work and needed a trouble report tracking application. MS-Access 97 was all I had at the time. Once I get something started, I almost never start anything from scratch after that. I always start a new applicatioin by cloning from an application that works.

It looks like I am going to have to do LSMC's import suggestion after all.

Ted Palmer
All,

Hula, Hula, Hallelujah..!! Shake your ass and win a thousand dollars and a trip to Hawaii..!! (I'll bet you don't know what movie that came from?)

It is working..!! See the screen shot attached. LSMC was right. It worked. Creating a new blank database and importing everything from the old database where the debugger didn't work fixed my problem. Everybody can see the yellow line where execcution stopped and the debugger is waiting for my next command.

I understand better now what JimD was saying about MS-Access applications are in one of 2 states: Running or Stopped. So really it is not a matter of being in debug mode. I get that from the VS2008 compiler. Where I have to manage my compiler options when I want to debug my VB.NET app by changing the compiler output from "Release" to "Debug" then recompile if I want execution to stop at my breakpoint. When I am done debugging, I delete all my breakpoints and set my compiler output option back to "Release" from "Debug", and recompile again for Release.

I'm not quite done though. Now that I have done the import, the navigation panel on the left of my MS-Access 2007 Designer IDE has changed so dramatically that I can't find some of my database objects. In my old accdb file the navigator had all the database objects grouped by type; i.e.: all the tables together, all the queries together, all the forms together, and all the reports together. Now it looks like all database objects are grouped by table with related queries, forms, and reports in the same group. My report parameter forms are not related to a table. So I haven't found them yet. Could somebody tell me how to change it back to the way I had it?

Thanks for everybody's help and patience. I'll wait awhile for an answer to my last question. Then with or without an answer I'll close the question by awarding points.

Ted Palmer
DebuggerIsWorking.bmp
All,

I found it. Sorry that was too easy. Just right click the title bar of the naviagtion panel, and select how to organize the database objects.

I'll get this beautiful agony over with.

Ted Palmer
Thank you so much. This has been a very big deal for me.

Ted Palmer
All,

LSMC was right about the import process not taking very long. By my stop watch it took only 22 seconds.

Ted Palmer