Solved Filter characters or remove spaces or allow particular characters

asadkhan

Registered User.
Local time
Today, 13:49
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
 
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
 
@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.
 
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

Back
Top Bottom