Code for checking length not working (1 Viewer)

Zara D

Registered User.
Local time
Yesterday, 18:13
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

  • Database2 - Copy_221017.zip
    375.1 KB · Views: 34

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:13
Joined
May 7, 2009
Messages
19,231
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

Top Bottom