Combo box change only if other text boxes have data

O

Opal

I have a combo box on a form that has three status options -
Open, Closed - NG and Closed - OK. All records in the
form are Open but the user can close them only if certain
conditions are met. For example, the record status
can be Closed - OK only if Countermeasures and
a body number are noted (two separate text boxes).
A record status can only be Closed - NG if comments
(separate text box)are give as to why no countermeasure
can be found.

How can I prevent the combo box change based on
these criteria?
 
J

John W. Vinson

I have a combo box on a form that has three status options -
Open, Closed - NG and Closed - OK. All records in the
form are Open but the user can close them only if certain
conditions are met. For example, the record status
can be Closed - OK only if Countermeasures and
a body number are noted (two separate text boxes).
A record status can only be Closed - NG if comments
(separate text box)are give as to why no countermeasure
can be found.

How can I prevent the combo box change based on
these criteria?

Use code in the BeforeUpdate event of the combo. If the combination is
invalid, warn the user and set Cancel to True:

Private Sub comboboxname_BeforeUpdate(Cancel as Integer)
If Me!comboboxname = "Closed - OK" Then
If IsNull(Me!Countermeasures) Or IsNull(Me![Body Number]) Then
MsgBox "Cannot close without filling in blah blah blah", vbOKOnly
Cancel = True
End If
End If
<etc for the other conditions>

John W. Vinson [MVP]
 
O

Opal

I have a combo box on a form that has three status options -
Open, Closed - NG and Closed - OK. All records in the
form are Open but the user can close them only if certain
conditions are met. For example, the record status
can be Closed - OK only if Countermeasures and
a body number are noted (two separate text boxes).
A record status can only be Closed - NG if comments
(separate text box)are give as to why no countermeasure
can be found.
How can I prevent the combo box change based on
these criteria?

Use code in the BeforeUpdate event of the combo. If the combination is
invalid, warn the user and set Cancel to True:

Private Sub comboboxname_BeforeUpdate(Cancel as Integer)
If Me!comboboxname = "Closed - OK" Then
If IsNull(Me!Countermeasures) Or IsNull(Me![Body Number]) Then
MsgBox "Cannot close without filling in blah blah blah", vbOKOnly
Cancel = True
End If
End If
<etc for the other conditions>

John W. Vinson [MVP]

Thank you, John. That really helped!



"Expected: Then or GoTo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top