Clear Fields (1 Viewer)

capogna1

Member
Local time
Today, 18:15
Joined
Aug 8, 2019
Messages
46
Good morning!

I have this code to personalize my error message pertaining duplicate record:

Private Sub Form_Error(DataErr As Integer, Response As Integer)

Const ERR_DUPLICATE_INDEX_VALUE = 3022
Dim strMsg As String

If DataErr = ERR_DUPLICATE_INDEX_VALUE Then
strMsg = "This record cannot be added to the database." & vbCrLf
strMsg = strMsg & "It would create a duplicate record." & vbCrLf & vbCrLf
strMsg = strMsg & "Changes were unsuccessful."

MsgBox "Error Number: " & DataErr & vbCrLf & vbCrLf & strMsg, _
vbCritical + vbOKOnly, "Please search by SSN and add encounter to existing Veteran."

'Set focus to the offending control
Me.Patient_SSN_Entry.SetFocus

Response = acDataErrContinue 'prevent Access from displaying its own error message
Else
Response = acDataErrDisplay 'cause Access to display its own error message
End If

End Sub

I would need a code to clear my fields after the message, the fields are:
1664291724956.png

so the user can search from the combo box below and not worry about clearing the fields manually.
1664291885713.png


Thanks in advance.
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:15
Joined
Sep 21, 2011
Messages
14,317
Me.ControlName = Null or Me.Controlname = "" ?
 

capogna1

Member
Local time
Today, 18:15
Joined
Aug 8, 2019
Messages
46
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)

    Const ERR_DUPLICATE_INDEX_VALUE = 3022
    Dim strMsg As String

    If DataErr = ERR_DUPLICATE_INDEX_VALUE Then
        strMsg = "This record cannot be added to the database." & vbCrLf
        strMsg = strMsg & "It would create a duplicate record." & vbCrLf & vbCrLf
        strMsg = strMsg & "Changes were unsuccessful."

        MsgBox "Error Number: " & DataErr & vbCrLf & vbCrLf & strMsg, _
            vbCritical + vbOKOnly, "Please search by SSN and add encounter to existing Veteran."

        'Set focus to the offending control
        Me.Patient_SSN_Entry.SetFocus

        Response = acDataErrContinue 'prevent Access from displaying its own error message
    Else
        Response = acDataErrDisplay 'cause Access to display its own error message

    End If

End Sub
 

moke123

AWF VIP
Local time
Today, 18:15
Joined
Jan 11, 2013
Messages
3,921
I think gasman meant

Me.ControlName = Null

or

Me.Controlname = ""

One or the other, not both.
 

capogna1

Member
Local time
Today, 18:15
Joined
Aug 8, 2019
Messages
46
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)

    Const ERR_DUPLICATE_INDEX_VALUE = 3022
    Dim strMsg As String

    If DataErr = ERR_DUPLICATE_INDEX_VALUE Then
        strMsg = "This record cannot be added to the database." & vbCrLf
        strMsg = strMsg & "It would create a duplicate record." & vbCrLf & vbCrLf
        strMsg = strMsg & "Changes were unsuccessful."

        MsgBox "Error Number: " & DataErr & vbCrLf & vbCrLf & strMsg, _
            vbCritical + vbOKOnly, "Please search by SSN and add encounter to existing Veteran."

        'Set focus to the offending control
        Me.Patient_SSN_Entry.SetFocus

        Response = acDataErrContinue 'prevent Access from displaying its own error message
    Else
        Response = acDataErrDisplay 'cause Access to display its own error message
        
        Me.Patient_SSN_Entry = Null
        

    End If

End Sub


Private Sub Patient_SSN_Entry_Click()

End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:15
Joined
Sep 21, 2011
Messages
14,317
Yes, or use "" as already mentioned.
I was going to ask if that is the name of the control, but you seem to set focus to it without issues?
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:15
Joined
Sep 21, 2011
Messages
14,317
Don't you want to reset it on your error message?
 

capogna1

Member
Local time
Today, 18:15
Joined
Aug 8, 2019
Messages
46
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)

    Const ERR_DUPLICATE_INDEX_VALUE = 3022
    Dim strMsg As String

    If DataErr = ERR_DUPLICATE_INDEX_VALUE Then
        strMsg = "This record cannot be added to the database." & vbCrLf
        strMsg = strMsg & "It would create a duplicate record." & vbCrLf & vbCrLf
        strMsg = strMsg & "Changes were unsuccessful."

        MsgBox "Error Number: " & DataErr & vbCrLf & vbCrLf & strMsg, _
            vbCritical + vbOKOnly, "Please search by SSN and add encounter to existing Veteran."

        'Set focus to the offending control
        Me.Patient_SSN_Entry.SetFocus

        Response = acDataErrContinue 'prevent Access from displaying its own error message
    Else
        Response = acDataErrDisplay 'cause Access to display its own error message
       
        Me.Patient_SSN_Entry = Null
       

    End If

End Sub


Private Sub Patient_SSN_Entry_Click()

End Sub
This doesn't clear my field
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:15
Joined
Sep 21, 2011
Messages
14,317
You said you wanted to clear if you displyed your dupe message, yet you have the clear in the else block of the code?
Walk through your code line by line.
 

moke123

AWF VIP
Local time
Today, 18:15
Joined
Jan 11, 2013
Messages
3,921
Me.Patient_SSN_Entry = Null is in the wrong place.
 

capogna1

Member
Local time
Today, 18:15
Joined
Aug 8, 2019
Messages
46
Don't you want to reset it on your error message?
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)

    Const ERR_DUPLICATE_INDEX_VALUE = 3022
    Dim strMsg As String

    If DataErr = ERR_DUPLICATE_INDEX_VALUE Then
        strMsg = "This record cannot be added to the database." & vbCrLf
        strMsg = strMsg & "It would create a duplicate record." & vbCrLf & vbCrLf
        strMsg = strMsg & "Changes were unsuccessful."

        MsgBox "Error Number: " & DataErr & vbCrLf & vbCrLf & strMsg, _
            vbCritical + vbOKOnly, "Please search by SSN and add encounter to existing Veteran."

        'Set focus to the offending control
        Me.Patient_SSN_Entry.SetFocus
        Me.Patient_SSN_Entry = Null
            Me.Patient_Last_Name = Null
            Me.Patient_First_Name = Null

        Response = acDataErrContinue 'prevent Access from displaying its own error message
    Else
        Response = acDataErrDisplay 'cause Access to display its own error message
        
        


    End If

End Sub
 

capogna1

Member
Local time
Today, 18:15
Joined
Aug 8, 2019
Messages
46
You said you wanted to clear if you displyed your dupe message, yet you have the clear in the else block of the code?
Walk through your code line by line.
Thanks it worked that is exactly what I needed to do. Thanks so much!
 

Users who are viewing this thread

Top Bottom