enable/disable button based on textbox (1 Viewer)

Jere

Registered User.
Local time
Today, 14:20
Joined
Oct 31, 2012
Messages
12
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
 

missinglinq

AWF VIP
Local time
Today, 14:20
Joined
Jun 20, 2003
Messages
6,423
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)>
 

bob fitz

AWF VIP
Local time
Today, 19:20
Joined
May 23, 2011
Messages
4,726
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.
 

Jere

Registered User.
Local time
Today, 14:20
Joined
Oct 31, 2012
Messages
12
Thanks you both greatly for that. Now is there a way to have the button disabled right after clicking on it?
 

missinglinq

AWF VIP
Local time
Today, 14:20
Joined
Jun 20, 2003
Messages
6,423
...Now is there a way to have the button disabled right after clicking on it...

Bob gave you that:

...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)>
 
Last edited:

Jere

Registered User.
Local time
Today, 14:20
Joined
Oct 31, 2012
Messages
12
whoops. I read that, but when working on the code, I must have let that slip my mind ^^; thank you
 

Users who are viewing this thread

Top Bottom