By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,654 Members | 1,842 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,654 IT Pros & Developers. It's quick & easy.

Contingent Required Fields in a Form

P: 4
I have certain fields that I need to be required based on a previous answer in a combo box. Here is an example:

If the user selects "deposit" from the combo box for "Reimburse By" then I need the "Bank Name" combo box, account number field and "account type" combo box to become required.

Is this possible and if so how do I do it. TIA
Jan 3 '07 #1
Share this Question
Share on Google+
8 Replies


NeoPa
Expert Mod 15k+
P: 31,487
I believe it is possible.
However it's going to be very hard to help with so little information provided. Remember we only know what you tell us, and that, so far, is very little.
Please see (POSTING GUIDELINES: Please read carefully before posting to a forum) for help in formulating a question that will help us to help you.

MODERATOR.
Jan 3 '07 #2

P: 4
I believe it is possible.
However it's going to be very hard to help with so little information provided. Remember we only know what you tell us, and that, so far, is very little.
Please see (POSTING GUIDELINES: Please read carefully before posting to a forum) for help in formulating a question that will help us to help you.

MODERATOR.
I'm using Access 2000 and have created a form for employees to use to submit expenses they incur. I have certain fields and columns that are required and other fields and columns that I need to be required if the employee selects "deposit" from the column. If the employee selects "check" from the column then those fields should not be required. If "deposit" is selected then I have one field and two columns that I would like to be required. The field label is "account number" and the column labels are "bank name" and "account type"

I hope that clarifies! Thanks for any help :)
Jan 3 '07 #3

ADezii
Expert 5K+
P: 8,634
I have certain fields that I need to be required based on a previous answer in a combo box. Here is an example:

If the user selects "deposit" from the combo box for "Reimburse By" then I need the "Bank Name" combo box, account number field and "account type" combo box to become required.

Is this possible and if so how do I do it. TIA
Here is generic code that will not allow you to Save a Record if Deposit is
selected in the Reimburse By Combo Box and there are no values in one
or more of the Bank Name, Account Number, or Account Type Fields,
essentially making them required. Hope this is what you are looking for. It
resides in the BeforeUpdate() Event of the Form where the Update can be
cancelled should one of this conditions exist:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If Me![cboReimburseBy] = "Deposit" Then
  3.   If IsNull(Me![cboBankName]) Then
  4.     MsgBox "You must provide a Bank Name"
  5.     Me![cboBankName].SetFocus
  6.       Cancel = True
  7.         Exit Sub
  8.   End If
  9.   If IsNull(Me![txtAccountNo]) Then
  10.     MsgBox "You must provide an Account Number"
  11.     Me![txtAccountNo].SetFocus
  12.       Cancel = True
  13.         Exit Sub
  14.   End If
  15.   If IsNull(Me![cboAccountType]) Then
  16.     MsgBox "You must provide an Account Type"
  17.     Me![cboAccountType].SetFocus
  18.       Cancel = True
  19.         Exit Sub
  20.   End If
  21. Else
  22.   'Do whatever
  23. End If
  24. End Sub
Jan 3 '07 #4

P: 4
Here is generic code that will not allow you to Save a Record if Deposit is
selected in the Reimburse By Combo Box and there are no values in one
or more of the Bank Name, Account Number, or Account Type Fields,
essentially making them required. Hope this is what you are looking for. It
resides in the BeforeUpdate() Event of the Form where the Update can be
cancelled should one of this conditions exist:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_BeforeUpdate(Cancel As Integer)
  2. If Me![cboReimburseBy] = "Deposit" Then
  3.   If IsNull(Me![cboBankName]) Then
  4.     MsgBox "You must provide a Bank Name"
  5.     Me![cboBankName].SetFocus
  6.       Cancel = True
  7.         Exit Sub
  8.   End If
  9.   If IsNull(Me![txtAccountNo]) Then
  10.     MsgBox "You must provide an Account Number"
  11.     Me![txtAccountNo].SetFocus
  12.       Cancel = True
  13.         Exit Sub
  14.   End If
  15.   If IsNull(Me![cboAccountType]) Then
  16.     MsgBox "You must provide an Account Type"
  17.     Me![cboAccountType].SetFocus
  18.       Cancel = True
  19.         Exit Sub
  20.   End If
  21. Else
  22.   'Do whatever
  23. End If
  24. End Sub
Thanks for your help but I still can't get it to work.

It tells me "run-time error 2465' Microsoft access cannot find the field 'cboReimburseBy' referred to in your expression"

What am I doing wrong? Am I supposed to change something??
Jan 3 '07 #5

NeoPa
Expert Mod 15k+
P: 31,487
I don't mean to speak for ADezii, but as a general rule you need to adapt any code for your own database.
Unless you ask your question very well (very few do :() then the expert won't know enough about your situation (particularly the names of your controls and fields etc) to put the right names in their offering. What you need to do is read the code and make changes where appropriate for your database.
If this is too complicated for you at this stage, then you could post the relevant details in your question and most experts will tailor it to fit.
HTH.
Jan 3 '07 #6

ADezii
Expert 5K+
P: 8,634
I don't mean to speak for ADezii, but as a general rule you need to adapt any code for your own database.
Unless you ask your question very well (very few do :() then the expert won't know enough about your situation (particularly the names of your controls and fields etc) to put the right names in their offering. What you need to do is read the code and make changes where appropriate for your database.
If this is too complicated for you at this stage, then you could post the relevant details in your question and most experts will tailor it to fit.
HTH.
Thanks for the assistance. Sometimes I'll make assumptions about substitutions, renaming, etc. when I really should not. I try to do the best
with the information provided. BTW, you guys do a fantastic job with this
Forum.
Jan 3 '07 #7

NeoPa
Expert Mod 15k+
P: 31,487
Not a problem ADezii. And thanks for the comments.
I believe the best way to look after our members is to look after our experts.
We want as many members as possible, but the only way that will happen is if the experts keep things going. You experts are the valuable assets of the site. You can have a million members, but if you have no experts then you can bet there won't be a million members left tomorrow. Let me, or any of the other moderators, know if you have any problems (I don't expect you to have any - but if you do...).
Jan 3 '07 #8

P: 4
Ok I tried to figure out what I needed to change and I couldn't do it. My drop down box is named "reimburse by" I tried putting a space in there and it still doesn't recognize it. I guess I still don't know what I'm doing wrong. What info do you need to help me? Thanks and sorry for being so clueless :(
Jan 4 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.