Field becoming mandatory on condition

pedroghuk

Board Regular
Joined
Nov 27, 2008
Messages
52
Third and final query relating to this pesky inherited Database!<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p></o:p>
(This one is a problem I would have had if I had created the Database myself from scratch).<o:p></o:p>
<o:p></o:p>
In summary, I have a combo box, which when a particularly option is chosen a Message Box appears, advising the User to complete a further field x.<o:p></o:p>
<o:p></o:p>
My issue is that when this option if selected, I want field x to become mandatory. How do I do this? (Using validation in Table field properties or using VBA?).<o:p></o:p>
<o:p></o:p>
I have the following on-click procedure in place:<o:p></o:p>
<o:p></o:p>
Private Sub Speciality_AfterUpdate()
If Me.Speciality = "A&E" Then
MsgBox "Please determine the name of the on-call Physician who would admit the patient"
Me.Speciality.SetFocus
End If<o:p></o:p>

End Sub<o:p></o:p>
<o:p></o:p>
The Physician name would then be a mandatory requirement in field x.<o:p></o:p>
<o:p></o:p>
Any advice/guidance would be appreciated. Thanks.<o:p></o:p>
<o:p></o:p>
<o:p> </o:p>
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
In the Before Update event of the form is where you would enforce it.

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
   If Me.Specialty = "A&E" And Len(Me.YourTextBoxNameHere & vbNullString) = 0 Then
      Cancel = True
      MsgBox "You need to fill in a name of the on-call Physician if you have selected 'A&E'", vbExclamation, "Entry Error"
  End If

Be sure to change YourTextBoxNameHere to whatever control name is being used for the extra field information.
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,903
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top