UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> After Validation And Error Move Back To Correct, Access 2016    
 
   
damian.green
post Jan 20 2020, 04:26 PM
Post#1



Posts: 94
Joined: 24-October 18



After I find an illegal character in the [Event] field, I'm trying to keep the user in the field to correct it, before allowing them to move on.

The record is locked on the edited row, which is why I'm having to repaint (F5) to allow the record to be edited.

The behavior is that the message is showing the error, but then the cursor is moving to the next field on the continuous form. It should be going back to the [Event] field and be blinking at the end of the text.

Thoughts on where I've gone wrong?

CODE
Private Sub Event_AfterUpdate()
    Dim ClickResult As VbMsgBoxResultEx

    If ContainsIllegalCharactersInString([Event]) = True Then
        'Need to refresh the record so it can be changed.
        'https://access-programmers.co.UK/forums/showthread.php?t=177990
        Me.Repaint
        'Need to put the cursor back in the Event box, at the end position, so it can be fixed.
        'http://access.mvps.org/access/forms/frm0011.htm
        Me.Event.SetFocus
        Me.Event.SelStart = Me.Event.SelLength
        
    ElseIf ContainsIllegalCharactersInString([Event]) = False Then
        Exit Sub
    End If
End Sub
Go to the top of the page
 
cheekybuddha
post Jan 20 2020, 04:34 PM
Post#2


UtterAccess Moderator
Posts: 12,264
Joined: 6-December 03
From: Telegraph Hill


>> Thoughts on where I've gone wrong? <<

You are not using the best event. BeforeUpdate is better used for validation because you can cancel the update. There is quite specific syntax.

Also, with the code as you have it you are executing the function ContainsIllegalCharactersInString() twice which is not necessary - a simple Else would suffice.

I'll try and look up an example of BeforeUpdate for you.

hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
theDBguy
post Jan 20 2020, 04:36 PM
Post#3


UA Moderator
Posts: 77,494
Joined: 19-June 07
From: SunnySandyEggo


Hi. Normally, you would use the BeforeUpdate event to validate data entry. When you cancel the event, the cursor will stay on the same control.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
cheekybuddha
post Jan 20 2020, 04:41 PM
Post#4


UtterAccess Moderator
Posts: 12,264
Joined: 6-December 03
From: Telegraph Hill


Try it like this:
CODE
Private Sub Event_BeforeUpdate(Cancel As Integer)

  If ContainsIllegalCharactersInString([Event]) Then
    Me.Undo
    Cancel = True
  End If

End Sub


hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
damian.green
post Jan 20 2020, 05:08 PM
Post#5



Posts: 94
Joined: 24-October 18



Much more simple. How to get the cursor to be blinking at the end of the text in the field? Currently it selects all text, leading to the potential of someone hitting the backspace or delete unnecessarily.
Go to the top of the page
 
cheekybuddha
post Jan 20 2020, 05:24 PM
Post#6


UtterAccess Moderator
Posts: 12,264
Joined: 6-December 03
From: Telegraph Hill


CODE
Private Sub Event_BeforeUpdate(Cancel As Integer)

  If ContainsIllegalCharactersInString([Event]) Then
    Me.Undo
    MsgBox "The event contains illegal characters", vbOkonly + vbInformation, "Invalid"
    Me.[Event].SelStart = Len(Me.[Event])
    Cancel = True
  End If

End Sub

(nb Untested!)

--------------------


Regards,

David Marten
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    19th February 2020 - 07:43 AM