18 chracter

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I need code that can make calculate field [info] and then will do as this
explained:

If [info] > 18 chracter then
print 18 of the [info] & But if the last word be more than 18 character then
back to last space “ “ And them make new raw & vbCr & and continue with
printing 18 character and if last word is more than 18 then back to last “ “
and make new raw so On

Wich mean it can be print in the raw 5 character, because it depent on last
word if it is long. But if it is shot then it can be printed 18 character.


Thank you for your help
 
Jemsson

If [info] > 18 character

probably won't do what you expect, and probably won't work at all.

I suspect you want to know if the "length" of what's stored in [info] is
greater than 18 characters. If so, try:

If len([info]) > 18 then
...
 
Hi again

This code you wrote it worked inside a field on form after I removing "IF
....".

But this question I need to use it on Report and this code will be on Detail
/Event / On print/Visual Basic

Do you have any ide how to write the code after THEN ..... ? Because all
code before IF I already have it, such as place on the page and font etc.

If Len([info]) > 18 then

print 18 of the [info] & But if the last word be more than 18 character then
back to last space “ “ And then make new raw & vbCr & and continue with
printing 18 character and if last word is more than 18 then back to last “ “
and make new raw so On

Wich mean it can be print in the raw 5 character, because it depent on last
word if it is long. But if it is shot then it can be printed 18 character.

Thanks
 
Hello

Well, you don’t need to write above code I asked about that was after
IF........
because I wrote it and success, but now I found there is Detail High be
little when the text be more than 1 raw.

Do you know please how can I change “Derail.High†to be 2 cm ?
I mean by code in VB and not by properties setting.


Thank you
 
Here is a simple - not fully tested - function that should work in Access
2000 and later. Notice that this has no error-handling code built in.
Also, if a word exceeds the MaxLength then the entire word is returned as
one line. The assumption is that words are delimited by spaces.

For instance:
?SplitTolines("This is a test of my supercalifragilisticexpealidocious
simple code",18)
This is a test of
my
supercalifragilisticexpealidocious
simple code

'--------------------------------------------------------------------------
Public Function SplitToLines(StrIn, Optional MaxLength As Integer = 18)
'Takes a string and breaks it into 18 character lines
Dim vWords As Variant
Dim strOut As String
Dim iCount As Integer, iLength As Integer

If Len(StrIn & vbNullString) = 0 Then
SplitToLines = StrIn
Else
'Get all the words in the file
vWords = Split(StrIn, " ", -1, vbTextCompare)

For iCount = LBound(vWords) To UBound(vWords)
If iLength + Len(vWords(iCount) & "") < MaxLength Then
strOut = strOut & vWords(iCount) & " "
iLength = iLength + Len(vWords(iCount)) + 1
Else
strOut = strOut & vbCrLf & vWords(iCount) & " "
iLength = Len(vWords(iCount)) + 1
End If

Next iCount
SplitToLines = RTrim(strOut)
End If
End Function
 
I did a little more testing and came up with a modified version that has
error coding and strips off the final space on each line. Plus corrected an
error in the length calculation

Public Function SplitToLines(StrIn, Optional MaxLength As Integer = 20)
'Takes a string and breaks it into nn character length lines
'Works for Access 2000 and later
Dim vWords As Variant
Dim strOut As String
Dim iCount As Integer, iLength As Integer

On Error GoTo ERROR_SplitToLines

If Len(StrIn & vbNullString) = 0 Then
SplitToLines = StrIn
Else
'Get all the words in the file
vWords = Split(StrIn, " ", -1, vbTextCompare)

For iCount = LBound(vWords) To UBound(vWords)
If iLength + Len(vWords(iCount) & "") <= MaxLength Then
strOut = strOut & vWords(iCount) & " "
iLength = iLength + Len(vWords(iCount)) + 1
Else
strOut = RTrim(strOut) & vbCrLf & vWords(iCount) & " "
iLength = Len(vWords(iCount)) + 1
End If

Next iCount
SplitToLines = RTrim(strOut)
End If

EXIT_SplitToLines:

Exit Function

ERROR_SplitToLines:
SplitToLines = StrIn
'MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
" in procedure SplitToLines of Module Module1"

End Function
 
Back
Top