Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 08-12-2013, 09:28 AM   #1
Jere
Newly Registered User
 
Join Date: Oct 2012
Posts: 12
Thanks: 6
Thanked 0 Times in 0 Posts
Jere is on a distinguished road
enable/disable button based on textbox

I'm trying to do research through this forum, as well as general google searches, but I'm either not wording it right, or what I'm looking for is rarely done. I just can't wrap my head around it.

I'm trying to have a button in a form that, when clicked, will time stamp a text box already formatted for time. But once the text box is filled with a time, the button then disables itself for that record.

If I switch to another record where the text box is empty, the button will enable itself without closing the form, but obviously re-disable itself if I go to a record the text box is filled.

I'm sure I could use conditional formatting for it, but I don't think I'm going about it the right way. I already got a basic button built to timestamp

Jere is offline   Reply With Quote
Old 08-12-2013, 12:28 PM   #2
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,312
Thanks: 11
Thanked 719 Times in 669 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: enable/disable button based on textbox

Replacing txtTimeStamp and btnTimeStamp with your actual names:

Code:
Private Sub Form_Current()
 If IsNull(Me.txtTimeStamp) Then
  btnTimeStamp.Enabled = True
 Else
  btnTimeStamp.Enabled = False
 End If
End Sub

or, more cryptically

Code:
Private Sub Form_Current()
 btnTimeStamp.Enabled = IsNull(Me.txtTimeStamp)
End Sub

Linq ;0)>
__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)
missinglinq is offline   Reply With Quote
The Following User Says Thank You to missinglinq For This Useful Post:
Jere (08-12-2013)
Old 08-12-2013, 12:32 PM   #3
bob fitz
AWF VIP
 
Join Date: May 2011
Location: Essex England
Posts: 3,532
Thanks: 52
Thanked 684 Times in 666 Posts
bob fitz has a spectacular aura about bob fitz has a spectacular aura about bob fitz has a spectacular aura about
Re: enable/disable button based on textbox

Use code in the form's On Current event to interrogate the value of the text box that shows the time value. If it is null set the Enabled property of the button to True, if not set it to false.
Use code in the button's On Click event to enter a value in the text box. Then set the focus to another control (perhaps the text box) and then set the Enabled property of the button to false. Let us know if you need help with the actual code.

__________________
Bob Fitzpatrick
Microsoft Community Contributor Award (2011)
If this helped, please click the scales at the bottom left of this posting.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Many thanks.


I have never failed. I have found a thousand ways that do not work!
bob fitz is offline   Reply With Quote
The Following User Says Thank You to bob fitz For This Useful Post:
Jere (08-12-2013)
Old 08-12-2013, 02:03 PM   #4
Jere
Newly Registered User
 
Join Date: Oct 2012
Posts: 12
Thanks: 6
Thanked 0 Times in 0 Posts
Jere is on a distinguished road
Re: enable/disable button based on textbox

Thanks you both greatly for that. Now is there a way to have the button disabled right after clicking on it?
Jere is offline   Reply With Quote
Old 08-12-2013, 02:48 PM   #5
missinglinq
AWF VIP
 
missinglinq's Avatar
 
Join Date: Jun 2003
Location: Richmond (Virginia that is!)
Posts: 6,312
Thanks: 11
Thanked 719 Times in 669 Posts
missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light missinglinq is a glorious beacon of light
Re: enable/disable button based on textbox

Quote:
Originally Posted by Jere View Post

...Now is there a way to have the button disabled right after clicking on it...
Bob gave you that:

Quote:
Originally Posted by bob fitz View Post

...Use code in the button's On Click event to enter a value in the text box. Then set the focus to another control (perhaps the text box) and then set the Enabled property of the button to false....
Personally, I would only use the code in the OnCurrent event, so that the Command Button would only be Disabled after the Record is saved. I would also make the button essentially a 'toggle' button, in effect, so that if the users click on it, and realize that they've made a mistake, before leaving the Record, they can click the button again and reset the Textbox to Null. Something like

Code:
Private Sub btnTimeStamp_Click()
 If IsNull(Me.txtTimeStamp) Then
   Me.txtTimeStamp = Now()
 Else
  Me.txtTimeStamp = Null
 End If
End Sub


Replace Now() with Date() if you only need the date portion, rather than the date and time portion.

Linq ;0)>
__________________
The Devil's in the Details!
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


(All code solutions tested in Access 2003/2007, before posting, unless otherwise noted.)

Last edited by missinglinq; 08-12-2013 at 03:01 PM.
missinglinq is offline   Reply With Quote
The Following User Says Thank You to missinglinq For This Useful Post:
Jere (08-12-2013)
Old 08-12-2013, 03:05 PM   #6
Jere
Newly Registered User
 
Join Date: Oct 2012
Posts: 12
Thanks: 6
Thanked 0 Times in 0 Posts
Jere is on a distinguished road
Re: enable/disable button based on textbox

whoops. I read that, but when working on the code, I must have let that slip my mind ^^; thank you

Jere is offline   Reply With Quote
Reply

Tags
button , conditional fomatting , disable

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable/Disable textbox based on combobox value Ratib Hussaini Forms 2 01-07-2013 12:20 AM
Enable/Disable textbox when checkbox is checked for only one record at a time clloftus Forms 6 04-04-2012 09:31 AM
Enable / Disable textbox controlled by drop-down menu Sam81 Web Design and Development 4 03-26-2009 02:57 PM
how to enable/disable textbox based on checkbox value lamha Forms 3 08-30-2006 12:23 PM
Enable/disable button based on lookup on another table daninthemix Modules & VBA 2 01-12-2006 09:55 AM




All times are GMT -8. The time now is 09:38 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World