I have also made some additions to the code you've suggested just to
accomodate the need that some areas needed to be filled right aligned,
leaving some empty boxes from the starting box. I'm yet to figure out how
I
can convert it into an external function (not within the report's own
code).
The change I made is:
Sub PopulateBoxes2Fit(strControlName As String, boxCount As Integer)
'Code provided by John Spencer at microsoft.public.access.reports NG on
22/01/2005
Dim iLong As Integer
Dim pos As Integer
Dim strParse As String
strParse = Me(strControlName) & vbNullString
If Len(strParse) < (boxCount) Then
pos = ((boxCount) - Len(strParse)) + 1
Else
pos = 1
End If
For iLong = 1 To Len(strParse)
Me(strControlName & pos) = Mid(strParse, iLong, 1)
pos = pos + 1
Next iLong
End Sub
And I call it under detail's format event as : Call
PopulateBoxes2Fit("mTaxNo", 13)
As I had indicated to Duane, I'm desperately trying to find out how I can
place the characters at the center of the generated boxes. No results
yet.
:-(
BTW I have also made two more versions of the Duane's code; one to work
with
cm input and the other for inches. I will most probably be using the cm
version since it makes things easier when yo can exactly know the
measurements from the report's design view. The only difference is i.e.
lngLeft = BoxLeft becomes lngLeft = (BoxLeft * 567). I've also added
whichReport as suggested by Duane. Code now works from a module and needs
to
be called from the report. Just in case, it now is:
Public Function BoxIt(BoxLeft As Long, BoxTop As Long, BoxWidth As Long,
BoxHeight As Long, BoxNum As Long, whichField As String, whichReport As
Report)
'The function below is called under a report detail section's Format
event
as:
'Call BoxIt (2270, 75, 285, 338, 28, FullName, r_BE1_v2)
'Source code by Duane Hookom at microsoft.public.access.reports NG on
22/01/2005
'Modified into a function by Alp Bekisoglu on 22/01/2005
'All units are in twips, except for BoxNum.
'( 1 inch = 1440 twips, 1 cm = 567 twips)
Dim lngLeft As Long ' starting point of boxes (720 = 1/2 inch)
Dim lngTop As Long ' top point of boxes (360 = 1/4 inch)
Dim lngWidth As Long ' width of each box
Dim lngHeight As Long ' height of each box
Dim lngBoxCount As Long ' number of boxes
Dim strField As String ' the field to be parsed
Dim strReport As Report 'the report name where this function is used
lngLeft = BoxLeft
lngTop = BoxTop
lngWidth = BoxWidth
lngHeight = BoxHeight
lngBoxCount = BoxNum
strField = whichField
Set strReport = whichReport
Dim lngI As Long 'for looping
strReport.FontSize = 10
strReport.FontName = "Arial"
For lngI = 1 To lngBoxCount
strReport.Line (lngLeft + (lngI - 1) * lngWidth, lngTop)- _
Step(lngWidth, lngHeight), , B
strReport.CurrentX = lngLeft + (lngI - 1) * lngWidth
strReport.CurrentY = lngTop + 20
strReport.Print Mid(strField & Space(lngBoxCount), lngI, 1)
Next
End Function
Alp
John Spencer (MVP) said:
You are very welcome. And I'm glad it is working.
I've copied Duane's code and your modification to it. I will be
testing it to
see how well it works. I have an upcoming project where I may need to
do
something similar and if that code works I may use it vice setting up
all the
controls on a report to do the "boxes".
Alp wrote:
I did, of course. I also realized I am calling the function at the
wrong
place (OnOpen), now it is under the detail's OnFormat and works properly.
Sorry for the false alarm and thanks once again.
Alp
Not really.
Did you put the field FullName on the report in a control? It has
to be
there,
but it can be invisible (visible property of control set to No).
Alp wrote:
Hi John,
Actually the sub returns error.
If I use PopulateBoxes ("FullName"), then it gets stuck at the strParse
=
Me(strControlName) & vbNullString with: "Run-time error '2465' Microsoft
Access can't find the field 'Me.FullName' referred to in your
expression"
Any further suggestions?
Alp
With some creative naming you could use vba code to populate
the "box"
controls.
Then you could use a sub routine something like the following
UNTESTED
code.
Put a control on the report to hold the whole string and set
its
visible
property to false. Then name all the box controls with the
same name
plus
a
1-up number. Then call the UNTESTED code below for each
control that
has
to be
parsed out - Populate "FieldName"
Sub PopulateBoxes(strControlName As String)
Dim iLong As Integer
Dim strParse As String
strParse = Me(strControlName) & vbNullString
For iLong = 1 To Len(strParse)
Me(strControlName & iLong) = Mid(strParse, iLong, 1)
Next iLong
End Sub
fredg wrote:
On Sat, 22 Jan 2005 04:56:55 +0800, Alp wrote:
Hi Experts,
In need to design a report where each character of the
report data
(almos
all of them) needs to be displayed in a seperate box. The number
of
boxes
are pre-set for each report item thus parsing stops when
data
string
length
is reached and might leave some boxes empty. Same as
filling up a
pre-printed form.
What would be the proper approach? Something better than
Me.boxname =
Mid(string, ?, 1) for each box's source.
Thanks in advance.
Alp
To parse each character of a Field (or any string) into it's
own
control:
=Mid([FieldName],1,1)
=Mid([FieldName],2,1)
=Mid([FieldName],3,1)
etc.
in the appropriate unbound control.