views:

405

answers:

2

I'm trying to input ColumnWidths for a listbox in MS-Access2007 VBA and I'm having a problem getting it to take decimal numbers.

Code:

ResultList.ColumnWidths = "1;0.65;0.7;0.7;0.8;0.4"
Debug.Print ResultList.ColumnWidths

What gets put in for the ColumnWidths:

1;1;1;1;1;0

The way I want to get it to look after entered (based on what's there now):

1";0.65";0.7";0.7";0.8";0.4"

Question:

How do I get it to recognize that I want the decimals there so that it stops rounding? Is there a way to have quotation marks inside the string you want to enter?

+2  A: 
ResultList.ColumnWidths = "1 cm;0.65 cm;0.7 cm;0.7 cm;0.8 cm;0.4 cm"

Look at the documentation for ColumnWidths. It says

The ColumnWidths property holds a value specifying the width of each column in inches or centimeters, depending on the measurement system (U.S. or Metric) selected in the Measurement system box on the Number tab of the Regional Options dialog box of Windows Control Panel. The default setting is 1 inch or 2.54 centimeters. The ColumnWidths property setting must be a value from 0 to 22 inches (55.87 cm) for each column in the list box or combo box.

EDIT: You could specify the widths in inches as well.

ResultList.ColumnWidths = "1 in;0.65 in;0.7 in;0.7 in;0.8 in;0.4 in"
shahkalpesh
Um.... when I try ResultList.ColumnWidths = "1 in;0.65 in;0.7 in;0.7 in;0.8 in;0.4 in" I get 1440;936;1008;1008;1152;576
Bryan
Although it seems odd to me it is working so I'll just continue on. Thank you.
Bryan
It's converting your values to twips, or "twentieths of a point". There are 72 points in an inch, and 72 * 20 = 1440 twips in an inch.
Todd
Thanks Todd. Twips was a word used in VB6 days.
shahkalpesh
TWIPS is the way to do it, and always has been. Saves all that mucking about with having to specify the units every time. You just multiply your local default value by 1440.
David-W-Fenton
A: 

Shahkalpesh gave you the solution to your problem, but the answer to your actual question is to double up each quote mark in the string.

sWidths = "1"";0.65"";0.7"";0.7"";0.8"";0.4"""
Debug.Print sWidths

->  1";0.65";0.7";0.7";0.8";0.4"

It's very unbeautiful! This is how you would do it in a regular VB string variable, but it's not the correct syntax for that property.

Todd