Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Disable a button after the 1st click and Enable it !

Status
Not open for further replies.

KiraObito

MIS
Mar 18, 2012
6
MV
hi

I want to know how to Disable a button and after i go to the next record , then make it enable? (For information
i am making a Stock Control Database )
How can i achieve this?
here is my code but it only disables the command button but doesn't enable it when i go to next record.. :s

Private Sub Command61_Click()

Me!Command61.Enabled = False

'Check to see if there is any amount or is less than Total
If IsNull(Me.Paid) Or Me.Paid = "" Or Paid < Total Then
msgBox " The AmountPaid is Less than the Total Amount(Rf) ", vbCritical, " Error"
Exit Sub
End If

'Update the Stock
If Quantity_in_Stock < Quantit Then
msgBox " There is Not enough stock ", vbCritical, " error "
Else
Balance = Paid - Total
Quantity_in_Stock = Quantity_in_Stock - Quantit
End If
End Sub

Thanks in Advance
 
Enable it in the Current event procedure of the form.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya KiraObito . . .

I don't see your code getting past the [blue]Me!Command61.Enabled = False[/blue] line.
Microsoft said:
[blue]You can't disable a control while it has the focus.[/blue]
You need something like:
Code:
[blue]   Me(Screen.PreviousControl.Name).SetFocus
   Me!Command61.Enabled = False[/blue]
[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
KiraObito . . .

To whom are you directing you post [blue]18 Mar 12 11:17[/blue] ?

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
KiraObito . . .

Can you post your final code and do you still need an explanation regarding focus?

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
@TheAceMan1

it will be v grateful if u give me more explanation
about the focusing.

I used the same code but i used a code in another button so that when i press it again the Commnad61 button becomes enable.

If u want the code. Here it is :

Private Sub Command61_Click()

Me!Command61.Enabled = False

' To see if there is enough Stock
If Quantity_in_Stock < Quantit Then
MsgBox " There is Not enough stock ", vbCritical, " error "
Exit Sub
End If

'Check to see if there is any amount or is less than Total
If IsNull(Me.Paid) Or Me.Paid = "" Or Paid < Total Then
MsgBox " The AmountPaid is Less than the Total Amount(Rf) ", vbCritical, " Error"
Exit Sub
Else
Balance = Paid - Total
Quantity_in_Stock = Quantity_in_Stock - Quantit
End If
End Sub


Here is the Code to calculate the Total :

Private Sub Total_Click()
Total = Quantit * Price
End Sub


And here is the code to increase the Sales Number according to the records made :

Private Sub Sales_Number_Click()

Sales_Number = [Form].[CurrentRecord]

End Sub



Here is the Other button code:

Private Sub Command76_Click()
DoCmd.GoToRecord , , acNewRec
Me!Command61.Enabled = True
End Sub

Thanks in Advance
 
KiraObito said:
[blue] ... it will be v grateful if u give me more explanation about the focusing.[/blue]
You've seen where the focus resides as you tab thru controls on a form. To enter text in a specific textbox from the keyboard, that tetbox has to have the focus. You can tab thru to that textbox or use the mouse to set focus there directly. In the same way all other controls can have the focus.

The rule is:
Microsoft said:
[blue]Any control that's disabled can not receive the focus.[/blue]
So ... if the control already has the focus ... you can't disable it.

You can prove this by setting the [blue]Enabled[/blue] property for any control to [blue]No[/blue] (in form design view)... then open the form and using the tab key, watch the focus skip over the disabled control!

When you click your command button with the mouse the following is the sequence of events that occur:

[blue]On Enter[/blue] - [blue]On Got Focus[/blue] - [blue]On Click[/blue].

Since your using the [blue]On Click[/blue] event, you can see via the sequence, the button already has the focus before [blue]On Click[/blue]. The same sequence would occur for any other control.

Now that the button has the focus, [purple]we have to take into account the rule quoted above![/purple] When you try to [blue]disable[/blue] the button at this point, you'll get the following error message ...
Microsoft said:
[blue]Run-time error '2164'
You can't disable a control while it has the focus.[/blue]
... notifying you've violated the rule.

This is why I queried earlier on your code not getting past:
Code:
[blue]Private Sub Command61_Click()

   [red][b]Me!Command61.Enabled = False[/b][/red][/blue]
You should've gotton the error message here!

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top