Restricting fields

B

Bill

A couple questions that I don't know where to post.

1. I want to create a combo box that is not active until a combo box before
it is choosen. For example. Combo box 1 contains departments. If you
choose the department "Food and Beverage" I want the next combo box to become
active and populate with the sub-departments within the one choosen.

2. When the user changes the form from "Active" to "Closed" I want to
require a comment field and send an email. I have the email being sent now,
so I can arrange that.

This good is great and your help is VERY appreciated.
 
N

nathan_savidge

You can do by using the combobox1_Change event, then populate by:

Private Sub Combo0_Change()

me.Combo1.visible = true
me.combo1.rowsource = "SELECT [WHATEVER] FROM
WHERE
[SUBGROUP]=" & me.combo0.value
me.combo1.requery

End Sub

if i understand the 2nd bit, on the close event of the form, put in an input
box asking for the comment.
 
K

Klatuu

Reasonable methods, but wrong events, and incomplete solution

You should use the combo's After Update event. A Change event should rarely
be used. The Change event fires on every keystroke. (The value has changed)
That is not what you want. It is also not necessary to set the second
combo's row source in the event. It should be defined in its own row source
property with a WHERE Clause that filters on the value of the first combo.

So the correct method would be:

Private Sub Combo0_AfterUPdate()

Me.Combo1.visible = True
Me.Combo1.Requery

End Sub

For the required field, you use the Form Before Update event.

Private Sub Form_BeforeUpdate(Cancel As Integer)

If IsNull(Me.RequiredField) Then
MsgBox "This Field Is Required"
Cancel = True
End If

End Sub

This statement is vague.
When the user changes the form from "Active" to "Closed"
Does the OP mean there is a control to change the status of the current
record to Closed using a control or does he mean Close the Form?

If it is a control to change status, use the After Update of that control.
If it is when the user moves away from the record, use the Form After Update.
If it is when the form is closed, use the Form Unload Event rather than the
Close event. The Unload fires first and can be Canceled if there is an error
sending the Email which would allow the user to retry sending the email.

When the user changes the form from "Active" to "Closed"
--
Dave Hargis, Microsoft Access MVP


nathan_savidge said:
You can do by using the combobox1_Change event, then populate by:

Private Sub Combo0_Change()

me.Combo1.visible = true
me.combo1.rowsource = "SELECT [WHATEVER] FROM
WHERE
[SUBGROUP]=" & me.combo0.value
me.combo1.requery

End Sub

if i understand the 2nd bit, on the close event of the form, put in an input
box asking for the comment.

Bill said:
A couple questions that I don't know where to post.

1. I want to create a combo box that is not active until a combo box before
it is choosen. For example. Combo box 1 contains departments. If you
choose the department "Food and Beverage" I want the next combo box to become
active and populate with the sub-departments within the one choosen.

2. When the user changes the form from "Active" to "Closed" I want to
require a comment field and send an email. I have the email being sent now,
so I can arrange that.

This good is great and your help is VERY appreciated.
 

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