Cancel Event Procedure on Button if Combo Box is Empty

G

Guest

I have a database in Access 2000 that we use for tracking purchase request /
purchase orders. User are able to log in and complete a purchase requisition
by selecting a supplier from an "Approved Supplier List". If a supplier is
not on the list, they are not allowed to purchase from them.

In the database I have created a form called "Menu_Requisitions". On the
form, I have added a Combo Box "Combo123" that is populated via a query.
When the user clicks a button, a form "Requestor-Requisitions" is opened. In
this form, the field "Supplier" is automaticaly populated with the the value
chosen in "Combo123".

The problem I have is that if nothing is selected from "Combo123" then the
"Supplier" field is also left blank. It works fine if an item is selected
from the combo box. There is nothing to stop the user just clicking the
button and creating a record wihtout the supplier name. As the field
"Supplier" is locked, I do not want the validate that specific field before
update.

Is there a way to stop the form "Requestor-Requisitions" from opening if
"Combo123" is blank and to warn the user that something must be selected in
"Combo123" before the button will action its event procedure?

Thanks in advance.
 
M

Mark

You can have the command button disabled until the user selects a valid
entry from your combo box. In the AfterUpdate event of the combo box, you
can set the command button's Enabled property to "True" to allow the user to
click it. Or when the form opens, you can check the combo box to make sure
it's not empty, and if it is you can cancel the form open and open a message
box to tell the user why the form won't open.

Sample "Air Code":

Private Sub FormRequestor-Requisitions_Open(Cancel as Integer)
If Forms!Menu_Requisitions.Combo123.value = "" Then
Cancel=True
Msgbox "Please select a valid supplier first"
End if
End Sub
 
G

Guest

hi,
in the button's click event put this before the open form
"Requestor-Requisitions" code
if isnull(combo123) then
Msgbox("enter a supplier from the combo box")'
exit sub
end if
if the combo box is empty, the user gets a message and
code it terminated before the form Requestor-Requisitions
is opened. the user doesn't get the form until they enter
a supplier. the above is one technique to force required
input ie do this or code is terminated(exit sub).
-----Original Message-----
I have a database in Access 2000 that we use for tracking purchase request /
purchase orders. User are able to log in and complete a purchase requisition
by selecting a supplier from an "Approved Supplier List". If a supplier is
not on the list, they are not allowed to purchase from them.

In the database I have created a form
called "Menu_Requisitions". On the
 

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