Trim() Not Working for Me

ErikRP

Registered User.
Local time
Today, 08:03
Joined
Nov 16, 2001
Messages
72
I have a form on which users enter data. The text boxes are labelled F1, F2, F3, etc. and match the table name (box F1=field F1, etc).

On text box F7, users are to enter a client ID and it must be exact - no spaces are allowed. I have set up that box with =Trim([F7]) on the AfterUpdate property, but nothing changes - any spaces remain.

I am doing something simple wrong I'm sure - any ideas? I thought it might be the fact that the label is the same as the field name on the table, so I've tried changing that with no success.

Help!
 
Use the KeyPress event for the field:
If(KeyAscii = 32) Then KeyAscii = 0
 
Thanks David, I'll give that a try, but that still doesn't explain why Trim() isn't working for me. Am I using it incorrectly?
 
I think Trim only does leading and closing spaces, not in the middle of the string, but I've never used it, so that's just my inclination. By the way, if they're entering a clientID to match what's already in the list, have you considered using a combo box? That would reduce error considerably, and you could have it fill as it goes...

[This message has been edited by David R (edited 05-02-2002).]
 
Trim() does not operate on the "interior" of a string.
 
I only need to have leading and possibly trailing spaces removed. Trailing spaces don't seem to be entered to the table though, so it's mostly just the leading spaces.

As for the combo box idea, I had thought of that and even had it in place at one point but it was not working well with what we needed - too many instances of having to update the combo box.

I'm still not sure why =Trim([F7]) doesn't do anything. Is there possibly something on the form that might be getting in the way? This seems like a very simple function and to not work doesn't make sense.

[This message has been edited by ErikRP (edited 05-02-2002).]
 
Try referring to the field with Me.FieldName instead of just [FieldName].

I made a form with AfterUpdate set to:
Code:
Private Sub Text0_AfterUpdate()
    Me.Text0 = Trim(Me.Text0)
End Sub
and it worked fine.
What version of Access are you using? This was with Acc2k.

[This message has been edited by David R (edited 05-03-2002).]
 
DavidR, after using the code you suggested I was able to get it to work. I was using the expression and it didn't work - only the code. I don't know why but the important thing is that it works now.

Thanks!
 

Users who are viewing this thread

Back
Top Bottom