if/then command in access

D

Dennis Wolf

I am designing a database containing admission and discharge dates of
patients. A list box contains the options "admitted" and "discharged". I
would like to force the user to enter a discharge date if the "discharged"
option is selected. How can I programme this into the properties of the list
box? I.e. the user has to enter a discharge date before they can continue on
filling out the form. I am using a calender date picker from which the user
needs to select the date.
 
D

Dirk Goldgar

Dennis Wolf said:
I am designing a database containing admission and discharge dates of
patients. A list box contains the options "admitted" and
"discharged".

An option group or check box might be a better choice. (just my
opinion)
I would like to force the user to enter a discharge
date if the "discharged" option is selected. How can I programme this
into the properties of the list box? I.e. the user has to enter a
discharge date before they can continue on filling out the form. I am
using a calender date picker from which the user needs to select the
date.

Forcing the user to do one thing before they do anything else is usually
a bad idea -- hard to implement (though doable) and annoying to the
user. If I were doing this, I'd probably take a two-pronged approach:

1. In the AfterUpdate event of the Admit/Discharge control, use the
SetFocus method to put the focus into the DischargeDate control if
"discharged" was chosen.

2. In the form's BeforeUpdate event, don't allow the record to be saved
if Admit/Discharge = "discharged" and DischargeDate is Null.

Alternatively, if you really need to wait for the DischargeDate to be
filled in, you might disable all the other controls but Admit/Discharge
and DischargeDate, until that DischargeDate has been filled in or
Admit/Discharge has been changed to "admitted".
 
M

Mauricio Silva

Try this on the event on_exit, assuming you have only those 2 options in your
list box:

Select case List01
case "admitted":
' put here the code for admitted

case "discharged":
' put here the code to open date picker when discharged

end select
 
D

Dennis Wolf

Thanks both of you, I'll give it a try.

Mauricio Silva said:
Try this on the event on_exit, assuming you have only those 2 options in your
list box:

Select case List01
case "admitted":
' put here the code for admitted

case "discharged":
' put here the code to open date picker when discharged

end select
 
J

John Vinson

On Fri, 16 Sep 2005 08:21:03 -0700, "Dennis Wolf" <Dennis
I am designing a database containing admission and discharge dates of
patients. A list box contains the options "admitted" and "discharged". I
would like to force the user to enter a discharge date if the "discharged"
option is selected. How can I programme this into the properties of the list
box? I.e. the user has to enter a discharge date before they can continue on
filling out the form. I am using a calender date picker from which the user
needs to select the date.

You can't readily do this in the Listbox's event - but the Form's
BeforeUpdate event would let you do so:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Me!listbox = "Discharged" AND IsNull(Me!DischargeDate) Then
MsgBox "Please choose a discharge date", vbOKOnly
Cancel = True
End If
End Sub

John W. Vinson[MVP]
 

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