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

asadkhan

Registered User.
Local time
Today, 21:26
Joined
Oct 26, 2019
Messages
40
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, 23:26
Joined
Dec 7, 2018
Messages
352
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, 16:26
Joined
Jan 23, 2006
Messages
14,323
@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, 15:26
Joined
Apr 3, 2020
Messages
862
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