Solved simple calculations causing errors (1 Viewer)

miked18

New member
Local time
Today, 00:24
Joined
Jun 17, 2023
Messages
10
I have a form where i enter products, quantity, price. you can enter up to 8 products (it's ok) I have a button to update the quantities and calculate the the total price.(cmdUPDATETOTALS)
simple code. TotalQuantity = quantity1+quantity2, etc. TotalPrice = price1*quantity1+price2*quantity2, etc.

After form load, if i hit the cmdUPDATETOTALS with no values present, nothing happens. which is fine. If i enter data and hit the cmdUPDATETOTALS, it does the calculations fine.

I have other buttons to either cmdCLEARALLPRODUCT data or I can clear individual products with cmdCLEARPRODUCT1. these set the fields to "". example: me.quantity1 = ""

after I use either commands to clear the data, i start getting "runtime error 13, type mismatch" when I click the cmdUPDATETOTALS. this happens if any of the product fields are empty. if i just cleared product1, then entered new data into product1, its fine. if i clear product1 and product2 and only enter new data into product1, i get the error.

i dont get it. on form load, all of these values are set to ="", so why would clearing the data and setting it back to ="" cause a type mismatch error?

thanks.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 21:24
Joined
Oct 29, 2018
Messages
21,581
Hi. My first impression is you're hitting an issue with Nulls. However, I am wondering if anyone has already told you about having fields called quantity1, quantity2, price1, and price2? That's usually an indication of a bad design.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 05:24
Joined
Feb 19, 2013
Messages
16,704
these set the fields to "". example: me.quantity1 = ""
“” is a string- you can’t multiply strings wrong datatype

use 0 or null
 

GaP42

Active member
Local time
Today, 14:24
Joined
Apr 27, 2020
Messages
377
Setting a numeric field to null may be the source of the problems - but hard to tell without a sample/cut down version of the db / table defs and code.
The display of controls on the form does not necessarily mean the data structure is flawed. I presume that it is set up to allow quick entry for multiple line items, and not repeating columns in a table.
 

miked18

New member
Local time
Today, 00:24
Joined
Jun 17, 2023
Messages
10
I get that it may be bad design, but I am not sure how else to do it to accomplish what I am after. I appreciate all of the responses. @CJ_London, thanks. I see my error now and forgot that "" is a string. Setting the numeric fields to "0" fixed that. Thanks.
 

Users who are viewing this thread

Top Bottom