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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enable or Disable Specific command button on SubForm 1

Status
Not open for further replies.

Gerbers404

Programmer
Jun 11, 2001
84
0
0
US
Good morning,

I'm having problems trying to enable/disable a specific command button on a subform. I want the command button to check the contents of a field in a record on the subform, insert the date if the field is null, and then disable the command button. Here is what I have so far, tied to the onClick event of the command button on the subform.

Code:
If IsNull(Me!FollowUpDate) = False Then
    MsgBox "Date has already been entered and cannot be changed.", vbOKOnly, "Field Locked"
    Me!FollowUpBy.SetFocus
    Me!cmdMarkFollowUp.Enabled = False
Else
    Me![FollowUpDate] = CDate(Date)
    Me!FollowUpBy.SetFocus
    Me!cmdMarkFollowUp.Enabled = False
End If

Unfortunately, this code disables the command button in every record of the subform, and I only want it to disablle the one in the current record.

Is there a way to do this?

Thanks!



Gerbers404
 
If you're subForm is a continuous form, the Command button will be disabled. If it is not, you just need to put some code in the OnCurrent event to Enable or Disable the command button.

I am what I am based on the decisions I have made.

DoubleD [bigcheeks]
 
Thanks DoubleD,

The subForm is a continuous form, there's no way to set the properties of an individual cmdButton? Could the control be referenced by index number?

Gerbers404
 
You can still make your code work, you just can't disable the command button for each record.

Code:
If IsNull(Me!FollowUpDate) = False Then
    MsgBox "Date has already been entered and cannot be changed.", vbOKOnly, "Field Locked"
    Me!FollowUpBy.SetFocus
Else
    Me![FollowUpDate] = CDate(Date)
    Me!FollowUpBy.SetFocus
End If

Assuming your command button is in the detail section of your subform, this code should work.



I am what I am based on the decisions I have made.

DoubleD [bigcheeks]
 
Thanks DoubleD,

I had already changed that. I was hoping to clean it up a little and even make the button invisible to make it more frinedly for the users, but I will go with this solution.

Thanks again.

Gerbers404
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top