Code lines ignored

F

Fernando Oliveira

Good afternoon,

I have a strange problem with the following code:

Private Sub Fechar_Click()
On Error GoTo Err_Fechar_Click

1 Me.FrmOrçComponentesSub.Requery
2 DoCmd.GoToControl (OrcSubReferência.Name)
3 Me.OrcSubPreçoEuro = Me!FrmOrçComponentesSub![SubTotal]
4 Forms![frmOrçcomponentesMain]![OrcSubPreçoEuro] =
Me.FrmOrçComponentesSub.Form!SubTotal
5 DoCmd.Close

Exit_Fechar_Click:
Exit Sub

Err_Fechar_Click:
MsgBox Err.Description
Resume Exit_Fechar_Click

End Sub


The problem is that when it runs on ACCESS 2007, everything works fine. When
it runs in ACESS 2000, lines 2,3,4 are ignored. However, in ACCESS 2000, if I
insert a breakpoint at line 1 and I continue the code after the break, all
lines are executed correctly.

I get no compilation errors or any other kind of errors.

I tend to believe that the problem is the VBA version (6.5.1040 in ACCESS
2007 vs. 6.0.8714), but as far as I know, there is no way to update VBA
version of ACCESS 2000.

Any help would be appreciated.
 
F

Fernando Oliveira

Thank you for your reply Allen,

I followed the steps but the result is the same.
 
A

Allen Browne

Okay: I'm not sure what your code is trying to do, but perhaps you could try
something like this:

Me.[FrmOrçComponentesSub].Form.Recalc
Me.OrcSubPreçoEuro = Me.[FrmOrçComponentesSub].Form![SubTotal]
Me.Dirty = False
Me.Recalc
Forms![frmOrçcomponentesMain].Form![OrcSubPreçoEuro] = _
Me.[FrmOrçComponentesSub].Form!SubTotal

The suggestions are:
a) Include the .Form bit when referring to subforms. If this idea is new,
see:
http://allenbrowne.com/casu-04.html

b) Include square brackets around names that have non-standard characters.

c) Use Recalc if you need to force it to update calculated totals.

You could also try adding the line:
Stop
at the top of the procedure. Then press F8 repeatedly to step through each
line and verify that it is executing. If you find that this works but it
doesn't when you remove the Stop again, understand it as a timing issue
(i.e. you are reading values that have been updated when you Stop, but are
not updated when you just run it.)

The core problem might be that you are storing a total, when it might be
better to normalize, i.e. to ask Access to calculate the total when you need
it rather than store it.
 

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