Full Version: You Entered An Expression That Has No Value
UtterAccess Forums > Microsoft® Access > Access Forms
The following code fires this error message.....you entered an expression that has no value. The textboxes, txtWeight and txtHeight, are bound to fields in a table.
What can I do to prevent this error, when the field is NULL?
If IsNull(Forms!frmAdmissions!frmBMI.Form.txtWeight) = True Or IsNull(Forms!frmAdmissions!frmBMI.Form.txtHeight) = True Then
Exit Sub
lngWeight = Forms!frmAdmissions!frmBMI.Form.txtWeight
lngHeight = Forms!frmAdmissions!frmBMI.Form.txtHeight

Forms!frmAdmissions!frmBMI.Form.txtBMI = (lngWeight * 703) / lngHeight ^ 2
Forms!frmAdmissions!frmBMI.Form.lblBMI.Visible = True
End If
Jeff B.
Based on that first "If" statement, you only care if the user entered either a height OR a weight.
o when you try to do math on them, what happens if one of them is null?!?
The user isn't entering them. The data is being imported from another system. Unfortunately, I don't have height and weight on some of the patients.
Jeff B.
You get to decide, then, what you want to have happen.
You don't get to do the calculation if one of the values is null. Your choice is to skip the calculation, or convert the null to an appropriate 'dummy' value (perhaps "1" if "divided by" or "0" if "times", or ...?)
I thought of that. I was hoping there would be a fancy, dancy method/function/property that I could use.
Also, depending on what kind of system you're importing the data from, it's possible that 'empty' fields are being imported as Zero-Length Strings rather than Nulls. Instead of
If IsNull(Forms!frmAdmissions!frmBMI.Form.txtWeight) Or IsNull(Forms!frmAdmissions!frmBMI.Form.txtHeight) = True Then
If Nz((Forms!frmAdmissions!frmBMI.Form.txtWeight, "") = "" Or Nz(Forms!frmAdmissions!frmBMI.Form.txtHeight, "") = "" Then
which checks for ZLS as well as Nulls.
Linq ;0)>
Thanx. Good point.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.