Solved Filter characters or remove spaces or allow particular characters (1 Viewer)

asadkhan

Registered User.
Local time
Today, 12:25
Joined
Oct 26, 2019
Messages
52
Hi all
I have a column type text, in beforeupdate event it queries the table whether that ID already exist or not, if it does, it prompts and then move to the record else it allows a new entry. Column is not a primary or foreign key it's just a unique column.
Sometimes we get spaces in this column when we copy paste it from other sources, I am trying to remove them through a function, which I call afterupdate event, function is tested in other places, but it doesn't work in this particular column and gives runtime error, because of before update code mentioned above. Any help will be much appreciated.
Regards
Asad
 

Eugene-LS

Registered User.
Local time
Today, 15:25
Joined
Dec 7, 2018
Messages
481
Sometimes we get spaces in this column when we copy paste it from other sources
Code:
Private Sub YourTextFieldName_AfterUpdate()
Dim s As String
Dim t As String
Dim i As Integer

'Clearing the field value of all characters except digits
    s = Me.YourTextFieldName & ""
    Me.YourTextFieldName = Null
    For i = 1 To Len(s)
        t = Mid(s, i, 1)
        If IsNumeric(t) Then
            Me.YourTextFieldName = Me.YourTextFieldName & t
        End If
    Next i

' ... next code ...

End Sub
 

jdraw

Super Moderator
Staff member
Local time
Today, 08:25
Joined
Jan 23, 2006
Messages
15,364
@asadkhan
I suggest you provide a few examples so readers see the issue in context.
You could facilitate things if you describe the chars to be removed. That is a before and after view.
 

strive4peace

AWF VIP
Local time
Today, 07:25
Joined
Apr 3, 2020
Messages
1,003
hi @asadkhan

>doesn't work in this particular column and gives runtime error, because of before update code

in the BeforeUpdate event, code should UNDO and then set Cancel=true if you're moving to another record ... then the AfterUpdate event shouldn't run ~
 

Users who are viewing this thread

Top Bottom