Greetings all,
I am hoping that someone here can provide a solution to an odd problem that I have run into with my project. I am using Access 2016 working on a single form. The form has four inputs and three buttons. Two of these are at the core of my issue.
I have a text field, txtref, which I use to enter manual references into. I have code that converts any letters to capitals.
Private Sub txtref_LostFocus()


Dim t As String  'Raw inital string input from user.
Dim e As String  'Final output


If Not IsNull(t) Then
    t = Me.txtref.Value
    e = UCase(t) 'UCase forces any leters to be captilaized.
    Me.txtref.Value = e
End If


End Sub
I am using a command button, cmdCancel, to abort an entry before it is saved.
Private Sub cmdCancel_Click()


Me.Undo
DoCmd.Close , , acSaveNo


End Sub
The form has a description field which is auto populated from a previous form. (this function works perfectly) I have a combo box for publisher, and a combo box for reference type. Both of these work just fine. The cancel button is throwing me for a loop. When the form opens, if I click cancel, the form closes without any records being created. If I enter a response into the publisher combo box and click cancel, the form closes without any records being created. However if I enter responses into publisher and reference type combo boxes and tab into the reference number text box and click cancel I get an error for "Invalid Use of Null". I tried changing the code to a Len (t) > 0 Then, and this worked, however the UCase function stopped working. I tried using a message box and If and Else statements to determine if it was just me missing something. One message was for an empty text field and the other was for anything being entered into the text field. What I found is that no matter what I do, as soon as the txtref box has the cursor it think that there is text there. I know I'm close, but I can't seem to put my finger on what it is that I am missing to make the cancel function work at any time.

Any help is appreciated. Thanks in advance.
While testing the buttons on my form today I noted something interesting.