473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Disable Button unless two specific fields both have data in them

I'm new to this site and new to Access so please forgive. I have a New Request form with a "SaveRecordButton" button that I need to disable if the user has entered data into either the cboNI textbox or the cboFS textbox and not the other. There are several other fields on the form but I only need to disable the SaveRecord button if the user has entered data into one of these two boxes and not the other. If one box has data the other also has to have data in it before the user saves the record. If both fields are null then the SaveRecordButton should work normally.

I've been trying to do this with Code Builder but can't figure out how to go about it. Thanks in advance!
Apr 28 '20 #1
1 1377
NeoPa
32,556 Expert Mod 16PB
First of all the two separate Controls (Not Fields.) that you are referring to should have Event Procedures for AfterUpdate and we assume (Let us know if not safe to.) that all saved records have either both or neither Field set (A Field refers to the items of data - typically within a table - whereas the items on a Form that give access to that data are Controls).

For simplicity, and tidiness of code, we create a separate subroutine procedure that determines if the SaveRecordButton CommandButton Control should be enabled or otherwise. This is then invoked wherever necessary.

So, to start with let's see what the sub procedure would look like :
Expand|Select|Wrap|Line Numbers
  1. Private Sub EnableSave()
  2.     With Me
  3.         .SaveRecordButton.Enabled = (IsNull(.txtNI) = IsNull(.txtFS))
  4.     End With
  5. End Sub
An example of what one of your Event Procedures should look like would be :
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtNI_AfterUpdate()
  2.     Call EnableSave
  3. End Sub
That should give you all you need. Let us know if it all makes sense or if you get stuck implementing it.

Before we finish I need to draw your attention to a problem you really don't need. "cbo" at the start of a name indicates to anyone reading the code that the item is a ComboBox Control. In your case you describe both of your Controls as TextBoxes. That is really not good. A little like learning to fire a gun and starting with your own foot. In my example code I've called these two Controls by the names you should be using.
Apr 28 '20 #2

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

Similar topics

10
by: sffan | last post by:
I am new to database programming and was curious how others solve the problem of storing encrypted in data in db table columns and then subsequently searching for these records. The particular...
13
by: Ian Davies | last post by:
Im trying to test if two fields have been entered at the same time I have tried many combinations but cant get it. My last effort was if(isset($_POST && isset($_POST)){ die('You can\'t select...
1
by: Aubyone | last post by:
Does any one know if there is a way to disable Button on the web page while the page is proceessing the command on the Server? To stop user clicking buttons once it has started a process.
7
by: Dave | last post by:
Hello All, These one may be a bit tricky, and what I'd like to do may not even be possible. I would love to hear any ideas you guys have for solving this. Here is the situation: I have a form...
3
parshupooja
by: parshupooja | last post by:
Hey all, I have button on page. OnClick event I am saving records to database, which takes couple of seconds, meanwhile if user becomes impatient and clicks again, it triggers save again. I want...
0
by: eyemustbecrazy | last post by:
Hi, I know how to export whole tables as follows... <elsnipo> 'Export This Table strTable = "tblthis" strSql = "SELECT " & strTable & ".* INTO " & strTable & " IN """ &
1
by: Marjeta | last post by:
I have a form with lots of questions and a submit button. The answers are captured in text fields. When <submit> is clicked, I want JavaScript to determine which fields have changed and submit...
6
by: Vishal P Patil | last post by:
This is the code that I have written in C# which shows the contains in the sample.log file. class FileRead { public void ReadData() { FileStream fs = new FileStream("sample.log",...
14
by: ephi | last post by:
I have an append query which is tied to the OnClick event of a button on my form. I want the query to run only if the values of either of 2 fields is updated on the form; the 'Location' field or the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.