form question

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

Guest

I made a form that generates a number when certain field is clicked on. The
problem that i have is that when i go back to the record and click on the
field, it generates a new number. I added another IF statement to the
existing code that supposed to make the field read only, but it still doesn't
work.

If companycode.Value <> Null Then
companycode.Locked = True
Else
If DCount("[CompanyCode]", "[company]") = 0 Then 'assigns 500 to
companycode = 1
Else
companycode = DMax("[CompanyCode]", "[Company]") + 1 'assigns
End If
End If
End Sub
 
tope12 said:
I made a form that generates a number when certain field is clicked
on. The problem that i have is that when i go back to the record and
click on the field, it generates a new number. I added another IF
statement to the existing code that supposed to make the field read
only, but it still doesn't work.

If companycode.Value <> Null Then
companycode.Locked = True
Else
If DCount("[CompanyCode]", "[company]") = 0 Then 'assigns 500 to
companycode = 1
Else
companycode = DMax("[CompanyCode]", "[Company]") + 1 'assigns
End If
End If
End Sub

Nothing is ever equal to Null, but also nothing is ever "not equal" to
Null -- because Null is "unknown". Use the IsNull function to find out
if something is Null:

If IsNull(companycode) Then
If DCount("[CompanyCode]", "[company]") = 0 Then
companycode = 1
Else
companycode = DMax("[CompanyCode]", "[Company]") + 1
End If
Else
companycode.Locked = True
End If
 
The initial If...Then should be

If IsNull(companyCode.Value) = True

in order to properly evaluate NULL. That will probably fix the problem,
or lest get you 1/2 way there.
 
Back
Top