Null Value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have code in a combobox AfterUpdate that I want to update a yes/no field if
the user enters certain values in the Diagnoses field. The problem I am
having is if the user makes a mistake and deletes the value He/She chose in
the combobox creating a null value, I get an error "Runtime error 94",
"Invalid use of Null".

I have tried several ways to fix this but none are working. The following is
the code:

Private Sub Diagnoses_AfterUpdate()

Dim stDiagnosesName As String

stDiagnosesName = [Diagnoses]

If stDiagnosesName = "Diabetes" Then
CronicCare = "Yes"

ElseIf stDiagnosesName = "Hypertension" Then
CronicCare = "Yes"

ElseIf stDiagnosesName = "Seizure Disorder" Then
CronicCare = "Yes"

ElseIf stDiagnosesName = "Asthma/COPD" Then
CronicCare = "Yes"

ElseIf stDiagnosesName = "Dialysis" Then
CronicCare = "Yes"

Else: CronicCare = "No"
End If
End Sub

How can I fix this problem?

Thanks,

Dennis
 
Don said:
I have code in a combobox AfterUpdate that I want to update a yes/no
field if the user enters certain values in the Diagnoses field. The
problem I am having is if the user makes a mistake and deletes the
value He/She chose in the combobox creating a null value, I get an
error "Runtime error 94", "Invalid use of Null".

You can't assign Null to a String variable. Instead use...

stDiagnosesName = Nz([Diagnoses],"")
 
Rick,

Your solution worked well.
--
Thanks,

Dennis


Rick Brandt said:
Don said:
I have code in a combobox AfterUpdate that I want to update a yes/no
field if the user enters certain values in the Diagnoses field. The
problem I am having is if the user makes a mistake and deletes the
value He/She chose in the combobox creating a null value, I get an
error "Runtime error 94", "Invalid use of Null".

You can't assign Null to a String variable. Instead use...

stDiagnosesName = Nz([Diagnoses],"")
 
Dennis

Just a comment, instead of using the IF statements consider using the CASE
statement. Access has limit to how many level of IFs that it can handles
 
Back
Top