click event procedure

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hi,

I have a registration form that allows users to enroll in
a class. After entering the required information in a few
fields/text boxes the user clicks on a command button that
adds the information in to the class table. Then I would
like the command button to be deactivated, so only one
record can be entered at a time.

How can I make the command button be disabled after the
user clicks the command button??? What do you suggest?

I know how to change the caption after the click event,
but I am not sure how to disable the command button. The
click event procedure is listed at the bottom of this
message. I have tried using the following code within the
click event procedure, but I am not able to run this
without an error occurring:

Else
Me.RegisterForClass.Visible = False
End If

When I run the operation I get an error message stating
that I cannot make the command button not visible when it
has the focus.

Below is the click event:

Private Sub RegisterForClass_Click()
On Error GoTo RegisterForClass_Error

If IsNull(Me.EmployeeID) Or Me.EmployeeID < 1 Then
MsgBox "You must enter your employee ID number.",
vbInformation, "Employee ID line"
Me.EmployeeID.SetFocus
ElseIf IsNull(Me.EmployeeFName) Then
MsgBox "You must enter your employee first name.",
vbInformation, "Empoyee First Name line"
Me.EmployeeFName.SetFocus
ElseIf IsNull(Me.EmployeeLName) Then
MsgBox "You must enter your employee last name.",
vbInformation, "Employee Last Name line"
Me.EmployeeLName.SetFocus
ElseIf IsNull(Me.WorkPhone) Then
MsgBox "You must enter your employee work phone
number.", vbInformation, "Employee Work Phone Number line"
Me.WorkPhone.SetFocus
ElseIf IsNull(Me.ClassID) Or Me.ClassID < 1 Then
MsgBox "You must enter a class ID number listed below
to enroll in the class.", vbExclamation, "Class ID needed"
Me.ClassID.SetFocus
Else
Me.RegisterForClass.Visible = False

End If

Exit_RegisterForClass_Click:
Exit Sub

RegisterForClass_Error:
MsgBox "Error # " & Err.Number & ": " & Err.Description
Resume Exit_RegisterForClass_Click

End Sub
 
At the end of your Click Event Procedure, *set the Focus to another Control
(can be a dummy Control)* on your Form before disabling or hiding the
CommandButton. You cannot disable or hide the CommandButton when it has the
Focus.
 
Back
Top