Code for checking length not working

Zara D

Registered User.
Local time
Today, 12:26
Joined
Sep 25, 2017
Messages
10
Hello,

I need your help wrt. the attached data base please. If you open the Entry form, you will see three cascading combo boxes (Procure 21, Contract and Contract Sub-type). There is a code, which sets the Contract and Contract Sub-type to " " every time Procure 21 is changed. It is all as it should be. However, before update at form's level, there is also a code, according to which, if Contract and Contract Sub-type are not populated, a warning box should pop up before the record is saved, as I don't want any blanks on my form. However, there seems to be an issue with the code. Would you be able to help please?

Thanks!

Zara
 

Attachments

test the ListIndex of each combo for -1,
meaning nothing is selected on the combos.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.cboContract.ListIndex = -1 Then
Cancel = True
MsgBox "Contract is blank!"
Me.cboContract.SetFocus
ElseIf Me.cboContractSubtype.ListIndex = -1 Then
Cancel = True
MsgBox "Contract Subtype is blank!"
Me.cboContractSubtype.SetFocus
End If
End Sub
 

Users who are viewing this thread

Back
Top Bottom