Romio_1968
Member
- Local time
- Today, 21:07
- Joined
- Jan 11, 2023
- Messages
- 126
Hello guys,
I have an annoying error that bothers me:
On a continuos subform i set a Combo Box named "Author_ID" with the Row Source on a query:
SELECT Author.Author_ID, Author.Author_Name FROM Author ORDER BY Author.Author_Name;
The Column Property is set to 2, and the Column Withs are 0,5
When landing on the combo, the user chooses value from a list or he may enter a new one, as well.
With each value he is choosing,a record is saved in a table, and the continuous form grows
The problem comes if the user is trying to delete (Backspace or del) the content of the Control. It doesn't mater if it is a prior saved field or the new one, thet is not yet saved in the table. This delition may be accidental. The form have a mecanism to delete saved records or undo de last.
If he clears the contros and basicaly the value stored in id is Null, or empty, or zero len (i don't know, probably Null, given the error that is trigerred), the message "You tried to asign the Null value to a variable that is not a Variant data Type." is trigered. The only way to get out from that trap is to hit twice the Esc. This will Undo the operation he is trying.
I want to get out from the trap in other way then hitting the Essc key.
If the record was saved, it must remain as it was. Is it is a new record, he wrote something in the control and he changed his mind, the control should remai also as it was.
Thank you
Late edit... it seems that I was indicating a wrong Error code. By trapping 3162 the issue was fixed.
Thank you
Solution:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3162 Then
If Me.ActiveControl.Name = "Author_ID" Then
If Len(Me.Author_ID) Then
MsgBox "No null value allowed", vbExclamation, "Atentie!"
Response = acDataErrContinue
Me.Undo
End If
End If
End If
End Sub
I have an annoying error that bothers me:
On a continuos subform i set a Combo Box named "Author_ID" with the Row Source on a query:
SELECT Author.Author_ID, Author.Author_Name FROM Author ORDER BY Author.Author_Name;
The Column Property is set to 2, and the Column Withs are 0,5
When landing on the combo, the user chooses value from a list or he may enter a new one, as well.
With each value he is choosing,a record is saved in a table, and the continuous form grows
The problem comes if the user is trying to delete (Backspace or del) the content of the Control. It doesn't mater if it is a prior saved field or the new one, thet is not yet saved in the table. This delition may be accidental. The form have a mecanism to delete saved records or undo de last.
If he clears the contros and basicaly the value stored in id is Null, or empty, or zero len (i don't know, probably Null, given the error that is trigerred), the message "You tried to asign the Null value to a variable that is not a Variant data Type." is trigered. The only way to get out from that trap is to hit twice the Esc. This will Undo the operation he is trying.
I want to get out from the trap in other way then hitting the Essc key.
If the record was saved, it must remain as it was. Is it is a new record, he wrote something in the control and he changed his mind, the control should remai also as it was.
Thank you
Late edit... it seems that I was indicating a wrong Error code. By trapping 3162 the issue was fixed.
Thank you
Solution:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3162 Then
If Me.ActiveControl.Name = "Author_ID" Then
If Len(Me.Author_ID) Then
MsgBox "No null value allowed", vbExclamation, "Atentie!"
Response = acDataErrContinue
Me.Undo
End If
End If
End If
End Sub
Last edited: