<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error Handling null value field with VBA in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13179081#M255</link>
    <description>&lt;P&gt;Instead of recovering, you need to validate the data first. You could use an event on each field to validate, like the OnExit event, or when they hit the Enter key, you could validate all the fields and exit the sub if it is invalid. First pop a message letting them know what field is invalid. You can even make it the active control.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Nov 2024 02:39:21 GMT</pubDate>
    <dc:creator>Ed__Jobe</dc:creator>
    <dc:date>2024-11-28T02:39:21Z</dc:date>
    <item>
      <title>Error Handling null value field with VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13176173#M254</link>
      <description>&lt;P&gt;Good day,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My form has several fields, all of which require a value. But if a null value is accidentally entered into any one of the fields, an error is triggered, and the VBA page is opened at the point of the error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to recover from the error seamlessly and let the user enter their intended value?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Nov 2024 01:52:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13176173#M254</guid>
      <dc:creator>greneebb</dc:creator>
      <dc:date>2024-11-27T01:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Error Handling null value field with VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13179081#M255</link>
      <description>&lt;P&gt;Instead of recovering, you need to validate the data first. You could use an event on each field to validate, like the OnExit event, or when they hit the Enter key, you could validate all the fields and exit the sub if it is invalid. First pop a message letting them know what field is invalid. You can even make it the active control.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2024 02:39:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13179081#M255</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2024-11-28T02:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Error Handling null value field with VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13184997#M256</link>
      <description>&lt;P&gt;Thanks for the guidance. However, it would mean validating several fields. Wonder if there is one validation that could validate all the fields globally.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Dec 2024 10:10:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13184997#M256</guid>
      <dc:creator>greneebb</dc:creator>
      <dc:date>2024-12-01T10:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: Error Handling null value field with VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13187938#M257</link>
      <description>&lt;P&gt;All you need is something like the following for each control that is used for data input. If all the fields are the same data type, then you could create a test function and in each Exit method, pass the function the control's Value property.&lt;/P&gt;
&lt;LI-CODE lang="visual-basic"&gt;Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
   'This function tests for an empty string in a TextBox.
   'If the value is empty, then focus is not allowed to go to the next control.
If TextBox1.Value = "" Then
        MsgBox "Value can't be null. Please fix.", vbCritical, "NULL Value"
        Cancel = True
    Else
        Cancel = False
    End If
End Sub
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Dec 2024 21:56:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13187938#M257</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2024-12-02T21:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: Error Handling null value field with VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13200974#M258</link>
      <description>&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 10:26:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13200974#M258</guid>
      <dc:creator>greneebb</dc:creator>
      <dc:date>2024-12-09T10:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Error Handling null value field with VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13201007#M259</link>
      <description>&lt;P&gt;I am getting close but still getting the error message "Type miss matched": Here is the code:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
   'This function tests for an empty string in a TextBox.
   'If the value is empty, then focus is not allowed to go to the next control.
If TextBox1.Value = "" Then
        MsgBox "Value can't be null. Please fix.", vbCritical, "NULL Value"
        Cancel = True
    Else
        Cancel = False
    End If
End Sub




Private Sub TextBox1_Change()

Call TextBox1_Exit(0)

 
 Me.Textbox4 = Round(Me.TextBox1 * 25.4, 3)
 Me.TopPer = Round((Me.TextBox1 * 25.4) * 3.142, 3)
 
End Sub&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 09 Dec 2024 10:43:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13201007#M259</guid>
      <dc:creator>greneebb</dc:creator>
      <dc:date>2024-12-09T10:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Error Handling null value field with VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13201952#M260</link>
      <description>&lt;P&gt;I assume it is this line raises the error:&lt;/P&gt;
&lt;PRE class="lia-code-sample line-numbers language-general" tabindex="0"&gt;&lt;CODE&gt;Me.Textbox4 = Round(Me.TextBox1 * 25.4, 3)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Even this line&lt;/P&gt;
&lt;PRE class="lia-code-sample line-numbers language-general" tabindex="0"&gt;&lt;CODE&gt;Call TextBox1_Exit(0)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;indeed prevent the focus from leaving TextBox1, its value still can be empty string, thus Round(Me.TextBox1 * 25.4) would fail when the text box's value is empty, or is a non-numeric value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, I do not think it is good idea to focus the textbox's value change to something else while user is typing/entering data into the text box. The user may be confused while he/she enters 1 and the textbox shows 25.400. You should do the validation with TextBox1_Exit: check the value being empty, or non-numeric value, or the numeric value may out of certain range... Only one of the cases occurs, you cancel the exit, and may want to let user know something is wrong (say, showing a message box, as you did).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 19:46:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13201952#M260</guid>
      <dc:creator>Norman_Yuan</dc:creator>
      <dc:date>2024-12-09T19:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Error Handling null value field with VBA</title>
      <link>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13204490#M261</link>
      <description>&lt;P&gt;In addition to &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/543921"&gt;@Norman_Yuan&lt;/a&gt; comments, I would recommend using Me.Textbox1.Value to explicitly refer to the value. Secondly, you can't Round a string. Use one of the Ctype functions to convert the text to a real for example. I also think that your form probably is not clearly informing the user what to enter. If you expect someone to enter an imperial value and you are automatically converting it to metric, for example, then have a box for imperial units, and then, in the OnChange event, calculate a value for a different field that is labeled 'metric/mm/etc'.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 04:28:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/error-handling-null-value-field-with-vba/m-p/13204490#M261</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2024-12-11T04:28:23Z</dc:date>
    </item>
  </channel>
</rss>

