Link to home
Start Free TrialLog in
Avatar of rmk
rmk

asked on

How to Calculate Character Width

In Access XP I have a continuous bound form with 2 controls:

- txtRecordID bound to RecordID
- txtRecord bound to Record

Each of these controls has FontName=CourierNew and FontSize=10 so that each character has the same width

The record is actually made up of 10 columns. So I have 10 labels in the form header. I also have a settings table that contains the names of each of these labels as well as its width in characters. In the Form_Load event I dynamically assign the the Left and Width attributes of each label so that it properly defines the start and end postion of each column. The detail section height is twice the height to txtRecord. Just above the text box I dynamically position some vertical lines to further show the field separation.

My problem is that the positioning of the form header labels and vertical lines in the detail section is never quite right across the entire width of txtRecord. I've tried the following base assumptions without total success:

dim lngUnitWidth as long

lngUnitWidth = 1440 / 12 ' the form grid is 24 x 24 and each character seems be be about 2 grid lines wide

lngUnitWidth = me.txtRecord.Width / 90 ' the text box is full at 90 characters

Any suggestions to help me with this dynamic alignement of labels and vertical bars?
Avatar of thenelson
thenelson

Are you saying the vertical lines and controls in the detail section does not line up with the labels in the header?

If so try:

[vertical line].left = [header label].left

[text box in detail section].left = [header label].left
[text box in detail section].width = [header label].width
Avatar of rmk

ASKER

The vertical lines in the detail section line up correctly with the labels in the header section. However neither of these always line up nicely between characters in the txtRecord text box.

Here is an example of the txtRecord contents for 1 record:

E200312020011900000000000221406000240001005302010797200400013156000001315609

This is my settings table that defines how wide each of the labels needs to be:

BankFieldID      Name      Length
1                      Code      1
2                      BatchDate      8
3                      BatchNbr      5
4                      CheckNbr      15
5                      TaxMap      15
6                      AssocNbr      2
7                      BillNbr      6
8                      TaxYear      4
9                      InvoiceAmt      9
10                      CheckAmt      9
11                      CheckChar      1
You can pick some ideas how to solve this here:

  http://www.lebans.com/autosize_textbox.htm

/gustav
What I would do is use Mid statements to parse out each piece of the record into separate text fields.  It sure would be a lot easier and a lot easier to read.  You could even format each text field  appropriately.  Each Mid statement can go in the text field control source property.  For example:
in the txtBatchDate control source put:    =Mid([txtRecord], 2, 8)

I'm assuming in the above example "E200312020011900000000000221406000240001005302010797200400013156000001315609" is a txtRecord
Avatar of rmk

ASKER

I don't want to parse out the fields because I have to allow the users to add or delete characters in the txtRecord text box and have everything shift accordingly. This is a lock box application and unfortunately the bank does not always send properly formatted data. I also have some buttons that let the user do bulk character inserts or deletes across a range of records. It all works quite nicely. By fiddling around, I've now got the labels lining up well enough that it's not worth any more effort.
I'm glad you got it worked out.
ASKER CERTIFIED SOLUTION
Avatar of RomMod
RomMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial