Access VBA going to break mode without reason!

A

Andrew R

....or so it seems.

I have a procedure behind the Current event of a form. The full code is
at the bottom of this post in case it sheds any light, though I can't
for the life of me spot anything myself.

The problem I have is that at the following line of code:
--
If txtEnrolled.Value < (lngMaxSize - 2) Then
--
the procedure always seems to drop to break mode. There's no error
message, but the line gets highlighted in the traditional way, as
though there was a problem. However, pressing F5 or F8 causes the code
to continue to execute with no errors, and it does exactly what I
wanted.

In short, the effect is of me having put a break point (there isn't one
- and I don't think there ever was on this line) or written
debug.assert false or similar, which is also not the case, as you can
see.

Does anyone have any suggestions? Am I being totally stupid?!

Thanks for your help

Regards
Andrew



With cboCourseID
.SetFocus
txtCourseHeader = .Text
End With
If IsNull(txtContractor) Then
txtContractor.Visible = False
txtInstructor.Visible = True
Else
txtContractor.Visible = True
txtInstructor.Visible = False
End If
txtEnrolled = Me.ChildForm.Form.RecordsetClone.RecordCount
If txtEnrolled.Value < (lngMaxSize - 2) Then
lblWarnings.Visible = False
ElseIf txtEnrolled.Value >= (lngMaxSize.Value - 2) And lngMaxSize.Value
txtEnrolled.Value Then
With lblWarnings
.Caption = "Event approaching capacity"
.Visible = True
End With
Else
With lblWarnings
.Caption = "EVENT FULL"
.Visible = True
End With

End If
 
R

RoyVidar

Andrew R said:
...or so it seems.

I have a procedure behind the Current event of a form. The full code
is at the bottom of this post in case it sheds any light, though I
can't for the life of me spot anything myself.

The problem I have is that at the following line of code:
--
If txtEnrolled.Value < (lngMaxSize - 2) Then
--
the procedure always seems to drop to break mode. There's no error
message, but the line gets highlighted in the traditional way, as
though there was a problem. However, pressing F5 or F8 causes the
code to continue to execute with no errors, and it does exactly what
I wanted.

In short, the effect is of me having put a break point (there isn't
one - and I don't think there ever was on this line) or written
debug.assert false or similar, which is also not the case, as you can
see.

Does anyone have any suggestions? Am I being totally stupid?!

Thanks for your help

Regards
Andrew



With cboCourseID
.SetFocus
txtCourseHeader = .Text
End With
If IsNull(txtContractor) Then
txtContractor.Visible = False
txtInstructor.Visible = True
Else
txtContractor.Visible = True
txtInstructor.Visible = False
End If
txtEnrolled = Me.ChildForm.Form.RecordsetClone.RecordCount
If txtEnrolled.Value < (lngMaxSize - 2) Then
lblWarnings.Visible = False
ElseIf txtEnrolled.Value >= (lngMaxSize.Value - 2) And
lngMaxSize.Value
With lblWarnings
.Caption = "Event approaching capacity"
.Visible = True
End With
Else
With lblWarnings
.Caption = "EVENT FULL"
.Visible = True
End With

End If

I think, if you just make a small change (Enter/Backspace), then save
and compile, does that help?

It might be a slight corruption issue, you could perhaps also try
/decompile on a copy of the db
http://www.granite.ab.ca/access/decompile.htm
 
P

Pieter Wijnen

Remove all breakpoints
if it doesn't solve it Repair & Compact
If Still no Luck Decompile (must hold shift down to bypass startup code)

Shortcut for Decompile:
<Path to Msaccess.exe> <Path to Db> /DECOMPILE

Pieter
 
A

Allen Browne

There is a timing issue here, Andrew.

The form's Current event fires when it loads a new record. After that, the
subforms have to load the records related to the one that was just loaded in
the main form (based on LinkMasterFields/LinkChildFields.) So trying to use
Form_Current to get the count of the records that will later be loaded into
the subform might be unproductive. See if you wan solve the problem by using
a DCount() on the subform's table instead.

If txtEnrolled not unbound (i.e. if it is bound to a field), you are
dirtying the record as soon as you move to it. This is almost always bad
practice. Altering the record just because you visited does nothing useful,
and the additional writes are likely to be harmful.

If that doesn't help, there are several other things that could be causing
you grief, including a name clash (solved by using Me to indicate what you
are talking about), a naming corruption (caused by Name AutoCorrect), or a
code corruption (solved with a decompile.) So, try this sequence:

1. Replace each occurance of:
txtEnrolled
with:
Me.txtEnrolled

2. Uncheck the boxes under:
Tools | Options | General | Name AutoCorrect
Explanation of why:
http://allenbrowne.com/bug-03.html

3. Compact the database to get rid of this junk:
Tools | Database Utilities | Compact/Repair

4. Close Access. Make a backup copy of the file. Decompile the database by
entering something like this at the command prompt while Access is not
running. It is all one line, and include the quotes:
"c:\Program Files\Microsoft office\office\msaccess.exe" /decompile
"c:\MyPath\MyDatabase.mdb"

5. Open Access, and compact again.

6. Open a code window.
Choose References from the Tools menu.
Uncheck any references you do not need.
For a list of the ones you typically need in your version of Access, see:
http://allenbrowne.com/ser-38.html

7. Still in the code window, choose Compile from the Debug menu.
Fix any errors, and repeat until it compiles okay.
 
A

Andrew R

Thanks for this Allen.

I haven't had a chance as yet to put into practice your various
suggestions, but will do so. Interestingly, before I logged in again to
read people's thoughts, I was looking at my code and wondered whether
there was a problem with there being both a text box called lngMaxSize
(I forgot to rename the control) and also an underlying field called
lngMaxSize. Therefore I renamed the textbox to txtMaxSize, and that
also seems to have cured the problem - perhaps coincidentally. I will
still compact, decompile and recompact and follow your other
suggestions...

Regarding the txtEnrolled field, it's unbound - used purely for
displaying delegate numbers enrolled on courses and for showing courses
that are over-subscribed.

Thanks again!

Andrew
 
A

Andrew R

Thanks for this Allen.

I haven't had a chance as yet to put into practice your various
suggestions, but will do so. Interestingly, before I logged in again to
read people's thoughts, I was looking at my code and wondered whether
there was a problem with there being both a text box called lngMaxSize
(I forgot to rename the control) and also an underlying field called
lngMaxSize. Therefore I renamed the textbox to txtMaxSize, and that
also seems to have cured the problem - perhaps coincidentally. I will
still compact, decompile and recompact and follow your other
suggestions...

Regarding the txtEnrolled field, it's unbound - used purely for
displaying delegate numbers enrolled on courses and for showing courses
that are over-subscribed.

Thanks again!

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top