Stop writing in a field

A

alvin Kuiper

Hi
I have thsi counting system there count Lines and Characters in a field
when a user come to 0 characters left i want to make it so the user cant
write anymore, i have dome it with setfocus on another field but then if the
user have 0 characters left and want to change something in the field, the
user can't that because it allways go to the other field.
Can someone help me here?

Alvin
 
B

BruceM

Somebody may be able to guess what you mean, but I suspect it is unclear to
most. What is "this counting sytem"? What do you mean by "when a user come
to 0 character left"? How do they "come to" that? Are they deleting
characters, or what? If so, how did the characters get there in the first
place? Are you using a form, or trying to write directly to the table? If
you are using code, what and where is it?
 
A

alvin Kuiper

Hi
Okay, i understand look here:
Dim strText As String
Dim nLines As Long
Dim antallinier As Long
Dim besked As Long
Dim tilbage As Long

antallinier = 2
tegn2 = 150
strText = Form_rettekursus.forudsætninger.Text & vbNullString

' Trim of trailing CR/LF, if any.
If Right(strText, 2) = vbCrLf Then
strText = Left(strText, Len(strText) - 2)
Else

End If

' Split on the CR/LF combination to see
' how many lines we have.
If Len(strText) = 0 Then
nLines = 0
besked = 0
Else
nLines = 1 + UBound(Split(strText, vbCrLf))
tal = (nLines * 50)

tegn = Len(forudsætninger.Text) + tal


End If




tilbage = antallinier - nLines
tegn3 = (tegn2 - tegn)
If tegn3 > 100 Then
tegn3 = 100
End If

lblforud.Caption = "Du har " & tilbage & " linier tilbage eller " & tegn3 &
" tegn"
If tilbage < 0 Or tegn = 100 Then
lblforud.Caption = "Du har ingen linier eller tegn tilbage"

End If
In this field a user only can write 100 characters so
when i write
If tilbage < 0 Or tegn = 100 Then
lblforud.Caption = "Du har ingen linier eller tegn tilbage"

Then i want to stop the user from write anymore.

Alvin


"BruceM" skrev:
 
B

BruceM

Where is this code (in what Event does it occur)? What happens when you try
to run it? More questions and comments inline.

alvin Kuiper said:
Hi
Okay, i understand look here:
Dim strText As String
Dim nLines As Long
Dim antallinier As Long
Dim besked As Long
Dim tilbage As Long

antallinier = 2
tegn2 = 150

What is tegn2?
strText = Form_rettekursus.forudsætninger.Text & vbNullString

What is Form_rettekursus.forudsætninger.Text? It seems it may be a field,
but if so, I don't think you want .Text at the end. I don't really
understand the Text property, but aren't you just trying to look at the
contents of the field? If so, how about Me.forudsætninger?
' Trim of trailing CR/LF, if any.
If Right(strText, 2) = vbCrLf Then

Where does the vbCrLf come from? How would it get to the end of
forudsætninger
strText = Left(strText, Len(strText) - 2)
Else

End If

' Split on the CR/LF combination to see
' how many lines we have.
If Len(strText) = 0 Then
nLines = 0
besked = 0
Else
nLines = 1 + UBound(Split(strText, vbCrLf))
tal = (nLines * 50)

What is tal? It is not defined. It it is a number it seems it will always
be at least 100. Is that correct?
tegn = Len(forudsætninger.Text) + tal

Why forudsætninger.Text? Why not strText? Also, what is tegn?
End If




tilbage = antallinier - nLines
tegn3 = (tegn2 - tegn)

tegn has a value only when Len(strText > 0). What is tegn if Len(strText) =
0?
If tegn3 > 100 Then
tegn3 = 100
End If

lblforud.Caption = "Du har " & tilbage & " linier tilbage eller " & tegn3
&
" tegn"

I speak English and a little French. It would help if I knew what some of
these words mean.
If tilbage < 0 Or tegn = 100 Then

Do you mean tegn3 = 100?
 
A

alvin Kuiper

Hi bruce
First : this code works allright..............
It is a danish DB so the text to the users is on danish
Look at this only :

If tilbage < 0 Or tegn = 100 Then
tilbage = variable there have how many characters the users have
left in a field.
Like i say user you can write 100 characters in this field, then
"tilbage" can see how many characters the user have left , all the code
running in the field property changing, so if a user start and write
AND then lblforud.Caption = "You have 97 characters left" when the user
have writing all 100 characters the lblforud.Caption ="You have no
characters left"

So when Tilbage = 0 or lblforud.Caption = 0 then i want to stop the user
from writing anymore.

Alvin



"BruceM" skrev:
 
B

BruceM

If the code works all right, what is the question? In what event do you
propose running this code? It seems to be more complicated than is
necessary, but if you want instant feedback I think you will need to run it
in the text box Change event or something like that, so that the code runs
after every key stroke. You could add a message box that would be activated
if the user attempts to enter over 100 characters (or you could just limit
the field length to 100). You could also use the text box validation
property to produce a message if the field length is too long, but the user
won't see that until they attempt to leave the text box.

I don't see why you bother to calculate tegn3 if you aren't going to use the
result of the calculation. This expression:
If tilbage < 0 Or tegn = 100 Then
either needs to reference tegn3 or you can leave out the code that
calculates tegn3. tegn will equal 100 only when there is one line of text,
if I read the code correctly. If there are 0 lines, tegn is null. If there
are two lines, tegn is 150.

I could suggest other things, but since you have decided you want to use
this code, all I can suggest is the Change event, or maybe the Key Down
event.
 
Top