Converting/Printing a Decimal Value

Kristoffer

New member
Local time
Yesterday, 19:54
Joined
Jun 3, 2013
Messages
4
This must be obviously simple, but I've been slamming my head against the wall, nevertheless. :banghead:

Bottom-line: I display decimal values in a combo box for selection. When I try to convert a selected decimal into a string, or simply print the value, it appears multiplying that integer by 4. However, the selected decimal does get written correctly in the raw DB table.

Here are my data structures:

Table "Hours_List":
Column Name: "Hours"
Data Type: "Number"
Field Size: "Decimal"
Format: "Fixed"
Precision: "18"
Scale: "2"
Decimal Places: "2"
Note: Every row increments by 0.25, starting at 0.25 and ending at 250.00

Table "Activity":
Column Name: "Activity_Duration"
Data Type: "Number"
Field Size: "Decimal"
Format: "Fixed"
Precision: "18"
Scale: "2"
Decimal Places: "2"

Here are my controls:

Combobox "cboDuration":
(Resides on form "ActivityEditor")
Format: "Fixed"
Decimal Places: "2"
Row Source: "SELECT [Hours_List].[ID], [Hours_List].[Hours] FROM Hours_List ORDER BY [Hours]; "
Row Source Type: "Table/Query"
Bound Column: "1"
Limit to List: "Yes"
Allow Value List Edits: "No"

Expression to check the value selected in the combo box:
Private Sub cboDuration_AfterUpdate()
Dim TestString as String

Debug.Print Forms!ActivityEditor!cboDuration

TestString = CStr(Forms!ActivityEditor!cboDuration)
Debug.Print TestString
End Sub

Example:
When I select "9.50" in the combo box, two "38"s print in the immediate (debug) window. What I want is for two "9.5"s to print!

Thanks for any help!!!
- Kris
 
I would start by NOT using decimal. It has some funny problems.
There is no Decimal data type in VBA—there’s no way to declare a constant with this type.
I use Double.
I am not sure if this will help your problem but, I would start there.

Dale
 
I would start by NOT using decimal. It has some funny problems...I use Double.
Dale

I switched everything to Double but get the same result. Thanks, though! Any other thoughts?
 
OKAY! I figured out what's happening, I'm just too new to Access and VBA to know how to correct it.

As I mentioned, every row in the "Hours" column in my "Hours_List" increments by 0.25. The auto-numbering key increments by 1. So, I'm thinking the combo box is returning the key value rather than the "Hours" value. What setting or syntax do I use to have the combobox selection return my "Hours" instead of the auto incrementing key value?
 
Last edited:
Since you really want to store the Hours, set your:
Combobox "cboDuration":
Bound Column: "2"
 
THANK YOU billmeye!! I was convinced the columns were indexed starting with "0" instead of "1." Problem solved!
 
Yes, you would think so since everywhere else counting starts with 0. Maybe MS will FIX that is Office 2016 and all your comboboxes will be calling out the wrong column. Leave it to them to do just something stupid.
 

Users who are viewing this thread

Back
Top Bottom