Debug and step into

L

Lars Brownie

Why does the debug and step into option only work in modules and not in
functions in forms? Or am I doing something wrong?

Thanks, Lars
 
B

boblarson

The debug and step into work for any VBA code - whether it is in form
modules, report modules, or standard modules. If you have a function written
in one of those modules, then it will work for it. But, in order to get it
to that point you either have to have an error, or provide a breakpoint.
And, if you set a breakpoint and it doesn't work, either it isn't firing the
event you think it is, or you might have the breakpoints turned off by having
the checkbox USE ACCESS SPECIAL KEYS unchecked in the TOOLS > STARTUP menu.


--
Bob Larson
Access World Forums Administrator

Tutorials at http://www.btabdevelopment.com

__________________________________
 
L

Lars Brownie

Thanks Bob,

This is strange. When I put the code beneath in a module, I can F8 my way
through it, without having to set a breakpoint or something else. However,
when I put the exact code in a form, F8 will result in one short sound (like
a cowbell) and then nothing happens. The setting you mentioned is checked
btw.

Lars
 
B

boblarson

When you say, "when I put the code in a form..." what do you mean? How are
you doing it? What is the code and where are you putting it?
--
Bob Larson
Access World Forums Administrator

Tutorials at http://www.btabdevelopment.com

__________________________________
 
L

Lars Brownie

Sorry. Forgot to paste the code, its:

Option Compare Database

Public Sub test()
Dim st As String

st = InputBox("Type OK")
If st = "OK" Then
MsgBox st
Else
MsgBox "Not OK"
End If

End Sub

The code is in the form's module.

Lars
 
B

boblarson

Looks like it should work just fine. How are you calling it? You need to
call it from an event like, say the click of a button:

Private Sub YourButtonname_Click()
Call test()
End Sub


--
Bob Larson
Access World Forums Administrator

Tutorials at http://www.btabdevelopment.com

__________________________________
 
L

Lars Brownie

The sub works fine, but the problem is that I'm not able to step through the
code (with F8), for instance to check variable values. When the code is in a
module I ám able to do that.

Lars
 
L

Lars Brownie

Not sure what you mean by break, but when I punt the breakpoint on the sub,
I see a red dot before the line and the line gets red and the text white. F8
causes in the cowbell and no further action. This happens in all databases.
I also tried a complete new database. I just don't understand why this
doesn't happen with the same sub in a module.

Lars
 
B

boblarson

Okay, just so we are on the same page -

Here's how you set a breakpoint:
http://www.btabdevelopment.com/main...kpointtostepthroughcode/tabid/58/Default.aspx

And for it to work you can't just hit F8. You have to initiate the event so
that it starts working first. So, if you have the breakpoint in the click
event of a button you need to click that button first before it will work.
--
Bob Larson
Access World Forums Administrator

Tutorials at http://www.btabdevelopment.com

__________________________________
 
L

Lars Brownie

You have to initiate the event so that it starts working first.

I didn't know that. Indeed now it's working in a form's module. Thanks for
sticking with me.

The funny thing still remains that a sub in a module doesn't need initiating
the event first. And it doesn't need breakpoints. When the cursor is
somewhere in the sub and you press F8 it will automatically start at the
first line of the sub (the line gets yellow) and with every F8 it will move
to the next step in the code. Any idea why there is this difference between
a module and a form's module?

Lars
 
B

boblarson

Probably because it is the difference between a function/sub and an EVENT
Sub. The event must happen for the sub to fire.
--
Bob Larson
Access World Forums Administrator

Tutorials at http://www.btabdevelopment.com

__________________________________
 
Top