Solved Weird VBA in RunTime (1 Viewer)

PaquettePaul

Member
Local time
Today, 00:31
Joined
Mar 28, 2022
Messages
107
Not really looking for a solution but thought I would share an experience.

I develop my code using Access 2019 and it operates in production using the free RunTime version of Access.

I have a routine in my financials generation process that calculates a base taxable amount and applies a 5% tax to it. initially, I stored the tax rate in a configuration record in the database (a backend version) and loaded the value into global variable gblGstRate (defined as double) at startup. I then applied that rate during the financials calc. A problem occurred in that the GST tax amount was not being calculated for the odd invoice. I went back and changed the SQL which retrieves the merchandise/service records records thinking that might be a problem as well as changing the gblGstRate to a value that is set to a fixed value of 0.05 during startup.

Ran the financials Routine in full Access and it worked as expected. Ran it in a split database in a RunTime environment and the GST was not calculated. Harrumph. Changed the code to show the taxable amount, the GST rate, and the derived tax amount. In the full access version, the tax rate was shown as 0.05 and, in the RunTime environment, the tax rate was shown as zero. Another harrumph.

So, enough with this nonsense, I changed the tax calculation to ”tax amount = taxable amount * 0.05”. Now the tax calculation works in both access environments.

Does anyone have any thoughts on why the problem occurred in the first place given that the code acts differently in the two environments?
 

ebs17

Well-known member
Local time
Today, 06:31
Joined
Feb 7, 2020
Messages
1,946
global variable gblGstRate
Global variables lose their value on unhandled errors.

Do you have error handling beyond "On Error Resume Next"? Are there actions that cannot be executed in the runtime version (opening a design view)?
 

PaquettePaul

Member
Local time
Today, 00:31
Joined
Mar 28, 2022
Messages
107
Nope. I have error handling and the form event and overall form level.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 05:31
Joined
Feb 19, 2013
Messages
16,616
If you change the file type from .accdb/e to .accdr you can test on your development machine- see if you can replicate the problem
 

Cotswold

Active member
Local time
Today, 05:31
Joined
Dec 31, 2020
Messages
528
I have always stored constants like VAT/Tax Rates on an always open form. They are loaded from the application system table on start-up. If they are amended for any reason in the system table, they are simply updated on the form. Mind you if they are all in a table, you can always just look them up as you need them I suppose. I've never used Globals or memory variables other than Privates just in case the OS blips. Comes from experiences in basic back in the olden days.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 05:31
Joined
Sep 12, 2006
Messages
15,658
@PaquettePaul

Clearly somewhere in your system the tax rate is not being picked up correctly. So some thoughts are that an error is causing your variables to lose their values, which could be the case. Alternatively, it might be a logic error.

If users are using run time, then there can't be a unhandled error (I don't think) or the programme would just stop.
So the error is most likely a logic error.

At the point you calculate the tax you could show a message if the tax rate is zero, or even if the tax calculation is zero. You would only get that when there is an error, and it might help you trace the circumstance that results in the zero. (I see you did something like that)

Maybe you have not defined the type of something, and in the run time it gets typed as an integer, not a double, and therefore 0.05 resolves as 0.
Do you have option explicit in all your modules? If not, do it in all modules, and in the your code editor, set "require variable declaration". It shouldn't be optional at all, but that's just the BASIC language for you. Not doing so can cause all sorts of strange behaviour.
 
Last edited:

Users who are viewing this thread

Top Bottom