cannot step into code access - vba

Using Access 2010 I cannot step into the code I have written for a form in Access.
Shouldn't I be able to step through it using the F8 key?
Does this indicate a damaged install of Access?

There are several conditions required for F8 to work.
You cannot be in a forms code module and hit F8 – it will not work since forms code is a class module.
If the code module is a class module, then again you cannot hit F8 when looking at code in that module (so a forms code module, and a code module that is a class object will not work.
Eg these:
Also if you hit F8 inside of a SUB or function that requires “parameters” then again F8 will not work. (since parameters are required).
So code in a class module will not work with F8 since you need to create an “instance” of that class object in code. Of course any routine (function/sub) that creates an instance of the class object will THEN allow F8 to step though such class object code.
And for a form, if you introduce a break line, or place a stop command in the code, then when the code runs, and encounters the breakpoint (or stop command), then at THAT point in time since a “instance” of the object exists, then F8 to single step will work.
So the difference between code/objects that must be instantiated before F8 works needs to be keep in mind.
Thus again, you can use F8 inside of forms code modules (they are class objects), but ONLY when an instance of the object (in this case a form) ahs been created and is running. So F8 can step though such code, but F8 cannot be used to start+run+debug such code until such time an instance of the object has been created.
So function/sub cannot have parameters, and cannot be in a form since such modules are class modules, and as noted you cannot use f8 inside of a class module either.

Try ALT+F11, then F8. Not my normal procedure. I found it by experimentation - pressing keys to see what happens.

You could force and error, like "mxgbox whatever" at the beginning of your class module. When VBA shows you the error message box you can click on "debug" and then continue with F8.

Bring up the VB Editor by hitting Alt+F11 then you can enter a break into any code on a code line - that way the code will stop there, and you can use F8 to step through or F5 to resume and run.
Oh, and if you don't know, you can enter a break by clicking the side panel or by pressing F9 on a particular line.

Related

How to step through VBA code behind a form? VBA error 2186: This property isn't available in Design view

I can run a macro under forms, but when I look at the code behind the form, I am not able to step through it all.
I hit the line
Dat = [Forms]![frmMenu]![dtmDate]
and get the error:
Is there a way to resolve this so I can continue to test each step of the macro?
I opened the code with ALT + F11.
I am trying to pinpoint the queries which cause the macro to take so long to run.
You can't hit f5 to run + debug code in a form. You can do this for a standard code module, but not for what we call a class module.
If you wish to debug/step code in a form? Launch the form (normal view). Then go to the code behind, say a button click, and now you can set a break-point.
So, single step, or debug of forms code requires you FIRST load the form as normal. (you can't thus use f5 to run such code). But, you CAN debug as per above.

VBA for Access trouble picking routine to run

I’m working on a project in access with a series of existing modules. There’s amain module that runs the whole thing, but often there are errors and to troubleshoot sometimes i want to pick a specific subroutine and run that by itself. The problem is, sometimes when i click run>run sub/userform sometimes it gives me a list of subroutines to pick from and sometimes it just runs the whole thing and i can never tell which it’s going to do before i click it. Does anyone know why this could happen? Is it where I’m putting my cursor or something?
Ok, now this works?
well, any code in a code module? You can place your cursor in that code, or even in the debug window, just type in the name of the routine. So, F5 to run the code, or you can as noted even call the code in the routine from the debug window.
eg:
Call MyTestSub("John")
Or if the routine does not have any parameters, then just type into the debug window this:
MyTestSub
HOWEVER!!!
If you open code for a form? Then you can't use F5 to run that code, and if you do, then your get that prompt. The reason for this is rather complex, but a "form" represents what we call a "class object". And you can't just "run" such code, you a have to first create a instance of that class. And even more complex?
Well in theory, you can actually ahve the SAME form open 5 times!!! (and have 5 instances of the form running! So F5, or even just typing in the sub name DOES NOT work for a class module, and that includes code inside of the form.
So, how to debug such code? Well, in most cases, you have to launch the form, and then in code behind, set a break-point. Now go click the button, or whatever.
You can also in theory call + run the code in a form, and you would do it this way:
Call Forms("Test").Mytest
but, the form would have to be open. So, you can't just run code inside of a class module, or forms code module. They are "special" and work different from a standard code module. As a result, F5 to run such code does not work. In fact, the form has to be loaded first. But, even then, hitting F5 inside of forms code modules does not work. You can put in break points, and single step code (and often form events can make that debug process quite a challenge).

New to Access How to run VBA code that doesn't have Sub?

Hi, I'm new to Access and I have a quick question.
I have a code that does not have 'sub'. And I was wondering how can I execute my code when I don't see any on Macro window? (Refer to the image attached)
My code start with function and declaration of variables!
It's very straight forward question but please comment below for any clarification if needed!
For you to be able to run a function with the press of a button for example, you must:
a) Put the function in a standard module, within the vba editor. Move the code to a new module and then call the function from a macro.
Or
b) Run the function from within an event vba sub like the click of button.
For both a sub, and a function in a code module, you can normally place the cursor in the sub/function and hit F5, and the code will run.
The above works for both a sub and function.
However, WHEN the sub/function has a parameter(s), then the F5 option will not work. In your screen shot the given function requires a parameter, so the long standing F5 to run such code as per above will not work. What occurs in this case is the macro prompt will launch as you point out.
Two suggestions:
Whack ctrl-g and your cursor should now be in the debug window, you can type in the name of the function (or sub) and SUPPLY the parameter.
Eg:
Test9999 "my first prameter"
The other means is to write a test code stub that passes the parmaters like this:
Public Sub RunMyFunction()
Test8888 "my paramter"
End Sub
And thus you can now hit F5. So you don’t need to run the code from a form or a button as suggested here. However, the instant the sub/function has a parameter(s), then you lose the F5 to run the code from the VBA IDE. You have to write a code stub, or as noted enter the function name + supply the required parameters of the correct type in the debug window to run the function.
However, to be fair, you can build a test form, and place code behind a button, but your question was in the context of the IDE and use of F5 to run such code.

VBA - Set Property in Subroutine to Automatically Step Over While Debugging

This question is specifically regarding the property get/let code in a class module but I think that the solution will be applicable to any subroutine.
There must be a property that tells vba to step over a function in break mode automatically (even when pressing the step into key/F8). Obviously such a thing exists for built in VB subs, classes and functions since the debugger doesn't step into them but I can't find a way to apply it to my code. What is it?!
It will make my life much easier when debugging.
Along with Shift+F8, there is also a button on the Debug toolbar.
Bonus Round:
If you forget to press Shift, and end up inside of the class anyway, you can Step Out by pressing Ctrl+Shift+F8
And go backwards by right clicking on the line you want to go back to and selecting "Set Next Statement".
One last note, the reason the debugger doesn't step into the "built in" classes is because that code is not written in VBA. It is hidden behind the COM Interop wall and written in an entirely different language all together.
If I understand correctly what you're asking, you need to step over instead of step into.
Try Shift+F8 instead of just F8.

How to step into VB.NET class code

I am debugging a VB.NET forms program which calls into properties and methods of a class which is part of the same project.
I put a break point in the form code but when I step through, it does not step into the class code.
Am I missing a setting?
Pressing F11 will take you into the method definition. F10 will step over. F5 will jump to the next break point. Or simply continue with the execution of your application until the application meets another break point on it's execution path.
This can can also be achieved by using actions located on the toolbar and in the context menu when using right click.
Make sure that you are pressing Step Into, not Step Over.