VB Code stops

  • Thread starter Thread starter Joop
  • Start date Start date
J

Joop

In an application that I developed the VB-code sometimes
stops executing as if there was a breakpoint. The code is
started by clicking a button. It stops at the first line
of the procedure, the codeline is marked yellow. When I
hit the continue button the code runs on normally.

Has anybody an idea how to fix it??

regards
Joop
 
Hi Nick,

Its nothing special, just some calculations: (or maybe the "on error resume
next" causes a problem?)

Private Sub CmdBerekenTotalen_Click()
Dim Sng1 As Long
Dim MemPMUKstn As Single
Dim MemAdmKstn As Single
On Error Resume Next

Sng1 = CLng(DSum("FldTotSubsidiabel", "TblProjectDeel", "FldProjectID =
" & Me!FldProjectID))
If Sng1 = Null Then Sng1 = 0
Me!FldAccKstn = DLookup("FldAccKstn", "TblAccKosten", "FldProjKstnVan <=
" & Sng1 & "and " & Sng1 & " < FldProjKstnTot")
'EVC
MemPMUKstn = Me!FldEVCUrenPMU * DLookup("FldKostprijs", "TblUurTarief",
"FldMedewCat = 'PMU'")
MemAdmKstn = Me!FldEVCUrenAdm * DLookup("FldKostprijs", "TblUurTarief",
"FldMedewCat = 'Admin'")
Me!FldEVCKstn = Me!FldEVCAantal * (Me!FldEVCTarief + MemPMUKstn +
MemAdmKstn)

Me!FldEVCLiftOh = ((Me!FldEVCUrenPMU * DLookup("FldVerkprijs",
"TblUurTarief", "FldMedewCat = 'PMU'") + Me!FldEVCUrenAdm *
DLookup("FldVerkprijs", "TblUurTarief", "FldMedewCat = 'Admin'")) _
- (MemPMUKstn + MemAdmKstn)) *
Me!FldEVCAantal

Me!FldTotSubsidiabel = Sng1 + Me!FldAccKstn + Me!FldEVCKstn + Me!TxtSub1 +
Me!TxtSub2 + Me!TxtSub3 + Me!TxtSub4 + Me!TxtSub5 + Me!TxtSub6 + Me!TxtSub7
Me!FldTotLiftOh = Val(DSum("FldLiftOh", "TblProjectDeel", "FldProjectID =
" & [FldProjectID])) + Me!TxtLoh1 + Me!TxtLoh2 + Me!TxtLoh3 + Me!TxtLoh4 +
Me!TxtLoh5 + Me!FldEVCLiftOh
End Sub


regards
Joop,
 
Joop

You have dim'd Sing1 as a Long and then test it for a Null in the second
line of your code. A Long Can NOT ever be Null, it must be a whole number.
It is likely that the problem is with the DSum on the first line. I
recommend that you wrap that DSum in a NZ() function like:

Sng1 = CLng(NZ(DSum("FldTotSubsidiabel", "TblProjectDeel", "FldProjectID = "
& Me!FldProjectID),0))

and see if that makes it all go away. You can kill the test for a Null in
the second line. You also should take the time to wrap all of your "Domain"
functions (DCount, DLookup, etc.) with a NZ()

Ron W

Joop said:
Hi Nick,

Its nothing special, just some calculations: (or maybe the "on error resume
next" causes a problem?)

Private Sub CmdBerekenTotalen_Click()
Dim Sng1 As Long
Dim MemPMUKstn As Single
Dim MemAdmKstn As Single
On Error Resume Next

Sng1 = CLng(DSum("FldTotSubsidiabel", "TblProjectDeel", "FldProjectID =
" & Me!FldProjectID))
If Sng1 = Null Then Sng1 = 0
Me!FldAccKstn = DLookup("FldAccKstn", "TblAccKosten", "FldProjKstnVan <=
" & Sng1 & "and " & Sng1 & " < FldProjKstnTot")
'EVC
MemPMUKstn = Me!FldEVCUrenPMU * DLookup("FldKostprijs", "TblUurTarief",
"FldMedewCat = 'PMU'")
MemAdmKstn = Me!FldEVCUrenAdm * DLookup("FldKostprijs", "TblUurTarief",
"FldMedewCat = 'Admin'")
Me!FldEVCKstn = Me!FldEVCAantal * (Me!FldEVCTarief + MemPMUKstn +
MemAdmKstn)

Me!FldEVCLiftOh = ((Me!FldEVCUrenPMU * DLookup("FldVerkprijs",
"TblUurTarief", "FldMedewCat = 'PMU'") + Me!FldEVCUrenAdm *
DLookup("FldVerkprijs", "TblUurTarief", "FldMedewCat = 'Admin'")) _
- (MemPMUKstn + MemAdmKstn)) *
Me!FldEVCAantal

Me!FldTotSubsidiabel = Sng1 + Me!FldAccKstn + Me!FldEVCKstn + Me!TxtSub1 +
Me!TxtSub2 + Me!TxtSub3 + Me!TxtSub4 + Me!TxtSub5 + Me!TxtSub6 + Me!TxtSub7
Me!FldTotLiftOh = Val(DSum("FldLiftOh", "TblProjectDeel", "FldProjectID =
" & [FldProjectID])) + Me!TxtLoh1 + Me!TxtLoh2 + Me!TxtLoh3 + Me!TxtLoh4 +
Me!TxtLoh5 + Me!FldEVCLiftOh
End Sub


regards
Joop,


Joop said:
In an application that I developed the VB-code sometimes
stops executing as if there was a breakpoint. The code is
started by clicking a button. It stops at the first line
of the procedure, the codeline is marked yellow. When I
hit the continue button the code runs on normally.

Has anybody an idea how to fix it??

regards
Joop
 
In addition to Ron's comment, Null is the absence of a value. The value of
an item can't be equal to Null. So, for your If statement to work it would
have to be

If IsNull(Sng1) Then......

This is just for future reference because Ron is correct, Sng1 can't be
Null.

--
Wayne Morgan
Microsoft Access MVP


Joop said:
Hi Nick,

Its nothing special, just some calculations: (or maybe the "on error
resume
next" causes a problem?)

Private Sub CmdBerekenTotalen_Click()
Dim Sng1 As Long
Dim MemPMUKstn As Single
Dim MemAdmKstn As Single
On Error Resume Next

Sng1 = CLng(DSum("FldTotSubsidiabel", "TblProjectDeel", "FldProjectID =
" & Me!FldProjectID))
If Sng1 = Null Then Sng1 = 0
Me!FldAccKstn = DLookup("FldAccKstn", "TblAccKosten", "FldProjKstnVan
<=
" & Sng1 & "and " & Sng1 & " < FldProjKstnTot")
'EVC
MemPMUKstn = Me!FldEVCUrenPMU * DLookup("FldKostprijs", "TblUurTarief",
"FldMedewCat = 'PMU'")
MemAdmKstn = Me!FldEVCUrenAdm * DLookup("FldKostprijs", "TblUurTarief",
"FldMedewCat = 'Admin'")
Me!FldEVCKstn = Me!FldEVCAantal * (Me!FldEVCTarief + MemPMUKstn +
MemAdmKstn)

Me!FldEVCLiftOh = ((Me!FldEVCUrenPMU * DLookup("FldVerkprijs",
"TblUurTarief", "FldMedewCat = 'PMU'") + Me!FldEVCUrenAdm *
DLookup("FldVerkprijs", "TblUurTarief", "FldMedewCat = 'Admin'")) _
- (MemPMUKstn + MemAdmKstn)) *
Me!FldEVCAantal

Me!FldTotSubsidiabel = Sng1 + Me!FldAccKstn + Me!FldEVCKstn + Me!TxtSub1
+
Me!TxtSub2 + Me!TxtSub3 + Me!TxtSub4 + Me!TxtSub5 + Me!TxtSub6 +
Me!TxtSub7
Me!FldTotLiftOh = Val(DSum("FldLiftOh", "TblProjectDeel", "FldProjectID =
" & [FldProjectID])) + Me!TxtLoh1 + Me!TxtLoh2 + Me!TxtLoh3 + Me!TxtLoh4 +
Me!TxtLoh5 + Me!FldEVCLiftOh
End Sub


regards
Joop,


Joop said:
In an application that I developed the VB-code sometimes
stops executing as if there was a breakpoint. The code is
started by clicking a button. It stops at the first line
of the procedure, the codeline is marked yellow. When I
hit the continue button the code runs on normally.

Has anybody an idea how to fix it??

regards
Joop
 
Joop said:
In an application that I developed the VB-code sometimes
stops executing as if there was a breakpoint. The code is
started by clicking a button. It stops at the first line
of the procedure, the codeline is marked yellow. When I
hit the continue button the code runs on normally.

Has anybody an idea how to fix it??

Hi Joop. I suspect that somehow you've saved a break point without
meaning to. This has happened to me before. It seems unlikely IMO that
Sng1 being Null should have an effect like breaking code. Do you recall
having a break point on that first line at any point while writing the
proc? If so, what you probably did is save the routine before you
removed the break point.

I have two suggestions for solving this problem, if this is what it is.
One has worked for me and the other is a guess. The guess-solution is
easier/less risky. Try setting a break point on that line, and then
removing it, and then save the routine, and see if the problem goes
away. If you try this please post back to let me know if it works
because I've never tried it.

The solution I've used before is to decompile your database. This is a
somewhat risky endeavor, and you shouldn't try it on your only copy of
your db. It's an undocumented command IIRC. To do:

0) If you have a form set to open automatically when the db opens, go
into Tools->Startup and set the opening form to None.
1) MAKE A BACK UP OF YOUR DB. REALLY. NO FOOLING.
2) DON'T EVEN READ THE REST OF THIS POST UNTIL YOU'VE BACKED UP YOUR DB.
3) Create a shortcut to your db.
4) Open the properties sheet of the new shortcut.
5) Type " /decompile" at the end of the string in the Target box. Note
that's a space, and "/decompile".
6) Close shortcut property sheet. Double-click shortcut to open
database. If you're not using default security, you'll need to log in
as a user with Admin rights (I think).
7) After you've opened the database, open the VB window and go to the
Debug Menu->Compile option, and click it to re-compile your code. Now
you can reset your startup form, if you had one.

If you try this, let me know if it works for you.

HTH
spark
 
Back
Top