473,395 Members | 1,527 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,395 software developers and data experts.

Need to have a button disabled until a field is populated on a form

I have a form that requires a Print button at the bottom. I would like for this print button to be grayed out until information is populated in a certain field above it. I have tried numerous code and none of it works. Can anyone help?

Please be specific as to where to put the code. I am still learning which events do what.

Thank you!
Feb 23 '16 #1

✓ answered by Seth Schrock

The code to put in the OnLoad event is
Expand|Select|Wrap|Line Numbers
  1. Me.PrintBadge.Enabled = False
. A textbox doesn't return true or false, so your if statement will fail. Instead you should put the following:
Expand|Select|Wrap|Line Numbers
  1. If Me.AccessCardNumber & "" <> "" Then
  2.     Me.PrintBadge.Enabled = True
  3. Else
  4.     Me.PrintBadge.Enabled = False
  5. End If
Or the shorter
Expand|Select|Wrap|Line Numbers
  1. Me.PrintBadge.Enabled = ((Me.AccessCardNumber & "") <> "")

7 1409
Seth Schrock
2,965 Expert 2GB
In the AfterUpdate of the control that you want populated, you would set the enabled property of your print button to true or false depending on if the value in your control is acceptable or not.
Feb 23 '16 #2
But how would I write that out in code? I have tried the following and it does not work:

If Me.AccessCardNumber = True Then
PrintBadge.Enabled = True
Else
PrintBadge.Enabled = False
End if

The button is active at the start. I need it disabled at the start. Please help!
Feb 23 '16 #3
Seth Schrock
2,965 Expert 2GB
To have it inactive at the start, then you need to add a line of code to the form's OnLoad event.

What do you mean by not work? Do you get an error message, or does nothing happen? Is AccessCardNumber a checkbox?
Feb 23 '16 #4
By not work, I mean that when I run the form, the button is active. I would like it inactive until the field is populated. I do not receive error messages with the above code.

AccessCardNumber is a text field. Once someone types in a number, the "PrintBadge" button should become enabled and allow them to print it.

What code would I add to the OnLoad event?
Feb 23 '16 #5
Seth Schrock
2,965 Expert 2GB
The code to put in the OnLoad event is
Expand|Select|Wrap|Line Numbers
  1. Me.PrintBadge.Enabled = False
. A textbox doesn't return true or false, so your if statement will fail. Instead you should put the following:
Expand|Select|Wrap|Line Numbers
  1. If Me.AccessCardNumber & "" <> "" Then
  2.     Me.PrintBadge.Enabled = True
  3. Else
  4.     Me.PrintBadge.Enabled = False
  5. End If
Or the shorter
Expand|Select|Wrap|Line Numbers
  1. Me.PrintBadge.Enabled = ((Me.AccessCardNumber & "") <> "")
Feb 23 '16 #6
That worked! That you for your patience!
Feb 24 '16 #7
NeoPa
32,556 Expert Mod 16PB
An easier way is simply to change the control to Enabled = False in design mode and save it that way. This doesn't require code. Setting it afterwards does, of course, but the initial setting doesn't.

Just make sure you don't allow the form design to be saved when it's used. That's good advice generally, of course.
Feb 24 '16 #8

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

Similar topics

5
by: bart plessers | last post by:
Hello, Somewhere in my code I have <input TYPE="button" NAME="btnFirst" VALUE="<<" OnClick="GetFile('1')" DISABLED> I changed the layout of the INPUT with a stylesheet to INPUT { color:...
5
by: Mark Hannon | last post by:
I have been researching the "disabled" property for form data and wanted to know: - Does the disabled property supress the form item from being submitted? - Can the disabled property be applied...
27
by: Kim Webb | last post by:
I have a field on a form for project number. I basically want it to be the next available number (ie 06010 then 06011 etc). In the form I create a text box and under control source I put: =!=...
4
by: Mel | last post by:
how can i change disabled background on all form elements ?
3
by: Melon via AccessMonster.com | last post by:
If anyone could take a look at this, I could do with the help. Im running into 2 problems with my db. 1) I have a members section in my db. If a member is selected as senior, all fields apply...
7
by: micarl | last post by:
I'm trying to create a new email message from Outlook based on a query called Q_Email with the BCC field populated with the email address field in the query. When i run this code, the query...
4
by: Hiramicus | last post by:
Hi - I'm using Access 2003. I have an input form that I'm trying to link to multiple tables. I have a command button that updates all the tables with the ~40 textboxes which the user inputs the...
3
by: moonrb | last post by:
Hi, i am making A database. In this db there are many form with command buttons. Each command button executes many queries. These command buttons will not work properly if any field of the form...
1
by: Abdullah Tariqu | last post by:
I am using access 2007 form I want to disable add record button if any field of form is null else add record as per validation So pls help me Thanks in advance Abdullah
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.