set space size between characters

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

I made a report that I want to print out on pre-printed forms that
have bubble in columns. The columns have titles that I must fill in
by hand. However, the title area has little square blocks for each
character.
My question is. Is there a way to finally adjust the space between
characters in the object field in my report.

Instead of .... myfieldword

This ...........m y f i e l d w o r d
 
I would use the Print method in code to do this. For instance, I bound the
LastName field to a text box in the detail section of a report. Make the
text box invisible and position it about where you want your first character
to print. The following code will print each character from the last name
1/4" apart. You can adjust the font size, font face, intSpacing, etc to meet
your needs.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim strLastName As String
Dim intTop As Integer
Dim intSpacing As Integer
Dim intCharacter As Integer
Dim intLeftMost As Integer
intSpacing = 1440 / 4 '1/4 inch
strLastName = Me.LastName
Me.FontSize = 16
intLeftMost = Me.LastName.Left
intTop = Me.LastName.Top

For intCharacter = 1 To Len(strLastName)
Me.CurrentX = intLeftMost + (intCharacter - 1) * intSpacing
Me.CurrentY = intTop
Me.Print Mid(strLastName, intCharacter, 1)
Next
End Sub
 
Duane Hookom said:
I would use the Print method in code to do this. For instance, I bound the
LastName field to a text box in the detail section of a report. Make the
text box invisible and position it about where you want your first
character to print. The following code will print each character from the
last name 1/4" apart. You can adjust the font size, font face, intSpacing,
etc to meet your needs.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim strLastName As String
Dim intTop As Integer
Dim intSpacing As Integer
Dim intCharacter As Integer
Dim intLeftMost As Integer
intSpacing = 1440 / 4 '1/4 inch
strLastName = Me.LastName
Me.FontSize = 16
intLeftMost = Me.LastName.Left
intTop = Me.LastName.Top

For intCharacter = 1 To Len(strLastName)
Me.CurrentX = intLeftMost + (intCharacter - 1) * intSpacing
Me.CurrentY = intTop
Me.Print Mid(strLastName, intCharacter, 1)
Next
End Sub



I ran into an error.
At the first Me.NameDL I get "method or data member not found"
and ".NameDL" is highlighted. I guess the field name can't be found.

I am not sure where to put this code. I tried in the report and Query
event procedures.


Here is the code

Private Sub Command404_Click()
'Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim strLastName As String
Dim intTop As Integer
Dim intSpacing As Integer
Dim intCharacter As Integer
Dim intLeftMost As Integer
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("qryAnswerSheets", dbOpenDynaset)

counter = 0
Maxrecs = DCount("*", "qryAnswerSheets")
If IsNull(Maxrecs) Then
GoTo Error1
End If
DoCmd.GoToRecord acDataQuery, "qryAnswerSheets", acFirst

Do
counter = counter + 1


DoCmd.OpenReport "rptAnswerSheets", acViewPreview
'DoCmd.OpenQuery "qryAnswerSheets"
'NameDL.SetFocus
intSpacing = 1440 / 4 '1/4 inch
strLastName = Me.NameDL
Me.FontSize = 16
intLeftMost = Me.NameDL.Left
intTop = Me.NameDL.Top

For intCharacter = 1 To Len(strLastName)
Me.CurrentX = intLeftMost + (intCharacter - 1) * intSpacing
Me.CurrentY = intTop
Me.Print Mid(strLastName, intCharacter, 1)
Next

DoCmd.GoToRecord acDataQuery, "qryAnswerSheets", acNext
Loop Until counter = Maxrecs
GoTo Exit2

Error1:
End Sub
 
Did you bind your field to a control in the report's detail section? What is
the name of the control that you used? Is the value you want to print in the
field list of the report?

The code runs in the On Format event of the detail section of the report. I
assume this is where you want the characters spaced.
 
Duane Hookom said:
Did you bind your field to a control in the report's detail section? What
is the name of the control that you used? Is the value you want to print
in the field list of the report?

The code runs in the On Format event of the detail section of the report.
I assume this is where you want the characters spaced.

Yes that is where in the detail section. The bound control is
"qryAnswerSheets" and the bound field is "Name".

I think what you are saying is highlite the detail section and goto
properties and there will be the on format event procedure. There insert
the code.

Do I have to set a recordset for the query bound to the report or does this
code just works on the report control?
I think so. Maybe why the me is not seeing the bound field?

I will work on it and get back.
 
The solution I suggested assumes your report has a record source with a
field bound to a control. The field value is what you want to print in the
boxes/grid.
You should never name anything "name". Every object in Access has a name
property.
 
Duane Hookom said:
The solution I suggested assumes your report has a record source with a
field bound to a control. The field value is what you want to print in the
boxes/grid.
You should never name anything "name". Every object in Access has a name
property.

It works. I changed the name in my table to "LastName" and my queries all
changed automatically. That was cool. I forgot about the name issue.
What made it work was pasting the code into the detail section on format
event procedure like you said.
Thanks.
 
Jay said:
It works. I changed the name in my table to "LastName" and my queries all
changed automatically. That was cool. I forgot about the name issue.
What made it work was pasting the code into the detail section on format
event procedure like you said.
Thanks.


Is there away to remove the slashes from a date with this code?

4/25/2006 becomes 4252006 or 42506
 
Sure, just modify this line of code
strLastName = Me.LastName
to
strLastName = Replace(Me.LastName, "/", "")
 
Back
Top