• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 166
  • Last Modified:

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?
1 Solution
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
rmkAuthor Commented:
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:


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
Gustav BrockCIOCommented:
You can pick some ideas how to solve this here:


Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

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
rmkAuthor Commented:
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.
The question has been PAQ'd and the 250 points have been refunded.
Community Support Moderator

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now