Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Restricting Fields w/VBA 2

Status
Not open for further replies.

InsaneProgrammer

Programmer
Jan 17, 2001
44
US
I have two fields on my form, PurchaseEstimateNumber and ContractNumber, that cannot both contain a value or be null. One of the fields must always have a value. The code I wrote doesn't seem to work. I've tried putting it everywhere on the form (After Update, On Change, On Exit, etc..). Does anyone have a suggestion? THANKS!

If ([PurchaseEstimateNumber] <> Null) And ([ContractNumber] <> Null) Then
Beep
MsgBox &quot;The record cannot have a PE# and a Contract#&quot;

ElseIf ([PurchaseEstimateNumber] = Null) And ([ContractNumber] = Null) Then
Beep
MsgBox &quot;The record must contain a PE# or a Contract#&quot;

Else
End

End If
 
NEVER test for Null by using &quot;=&quot; or &quot;<>&quot; - both of these will always return False!

The correct way to test for Null is IsNull(...). Rick Sprague
 
I wonder if you could achieve this by either putting the code in the declarations, or the on_current section. In the on_currect section it will verify everytime you try to switch records, so it should work in theory.... James Goodman
j.goodman00@btinternet.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top