adding 0.1 in VBA

R

redFred

I have an frmInvoice that calls frmInvoiceExt via a button.

I would like the code attached to the button to open frmInvoiceExt to
increment frmInvoice's invoice number by 0.1. InvNum in the table and each
control are formatted number to one decimal place. frmInvoice is open and
hidden.

My code (attached to the frmInvoice button):

forms![frmInvoiceExt].form!InvNum = me.InvNum + 0.1

This results in the same invoice numbers (key, no dupes). That is, the 0.1
is not added. Interestingly, if I add a whole number (left of decimal) the
invoice number of frmInvoiceExt is correct, but I need the left of decimal
numbers to be the same...only the ".x" to be different.

The first invoice number should be (ex) 091234.0, the calling form should
assign a number (in this ex) of 091234.1 and I cannot get the 0.1 assigned.

Can anyone help?
 
J

John W. Vinson

I have an frmInvoice that calls frmInvoiceExt via a button.

I would like the code attached to the button to open frmInvoiceExt to
increment frmInvoice's invoice number by 0.1. InvNum in the table and each
control are formatted number to one decimal place. frmInvoice is open and
hidden.

My code (attached to the frmInvoice button):

forms![frmInvoiceExt].form!InvNum = me.InvNum + 0.1

This results in the same invoice numbers (key, no dupes). That is, the 0.1
is not added. Interestingly, if I add a whole number (left of decimal) the
invoice number of frmInvoiceExt is correct, but I need the left of decimal
numbers to be the same...only the ".x" to be different.

The first invoice number should be (ex) 091234.0, the calling form should
assign a number (in this ex) of 091234.1 and I cannot get the 0.1 assigned.

Can anyone help?

My guess is that your InvoiceNumber field is of the default Number type - Long
Integer. An Integer is by definition a whole number; changing the Format or
the Decimal Places property will not change this fact.

I'd recommend using a Decimal Number datatype with one decimal place, or...
better... a Text field with a bit more code to append a text string ".1"
rather than adding 0.1; for one thing this would let you retain leading
zeroes.
 
R

redFred

Thanks so much!

John W. Vinson said:
I have an frmInvoice that calls frmInvoiceExt via a button.

I would like the code attached to the button to open frmInvoiceExt to
increment frmInvoice's invoice number by 0.1. InvNum in the table and each
control are formatted number to one decimal place. frmInvoice is open and
hidden.

My code (attached to the frmInvoice button):

forms![frmInvoiceExt].form!InvNum = me.InvNum + 0.1

This results in the same invoice numbers (key, no dupes). That is, the 0.1
is not added. Interestingly, if I add a whole number (left of decimal) the
invoice number of frmInvoiceExt is correct, but I need the left of decimal
numbers to be the same...only the ".x" to be different.

The first invoice number should be (ex) 091234.0, the calling form should
assign a number (in this ex) of 091234.1 and I cannot get the 0.1 assigned.

Can anyone help?

My guess is that your InvoiceNumber field is of the default Number type - Long
Integer. An Integer is by definition a whole number; changing the Format or
the Decimal Places property will not change this fact.

I'd recommend using a Decimal Number datatype with one decimal place, or...
better... a Text field with a bit more code to append a text string ".1"
rather than adding 0.1; for one thing this would let you retain leading
zeroes.
 

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