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!

Disable command button

Status
Not open for further replies.

2manyerrors

Programmer
May 14, 2009
36
US
Hello,

I hope someone can help. I have a continuous form that searches for file and attaches the file path. I have the form to not allow deletions and modifications to the text box named "docpath". But now, I would like to disable the attach file command button when there is a path in the text box "docpath". The command button to attach files should only be enabled when there is no path inside the text box "docpath".
If anyone can help please. Thank you.
 
oops I found the spot to put the code, it's in the button property.

I'm getting an error though, it's saying that I cannot a control while it has the focus.

Any idea?
 
I mistyped the last post.

My error is; I cannot disable a control while it has the focus.

Any ideas?
 
Ok here's an update.

I placed the codes in the wrong place. I placed it into the docPath text box. Now it works but I ran into a new problem.

I have two text boxes. If I place the codes into both text boxes then it works find until I place my cursor into the text boxes in the new blank record, this is to add new records in my continuous form. When I do this, all the command buttons are enabled again? I'm trying to get only where new records can have the command button but all other records does not have the command button to change what is inside the docpath button.

Hope you or anyone can help.
 
2manyerrors . . .

The code should be in the forms [blue]On Current[/blue] event. Also, check to see if the button has focus before you disable it:
Code:
[blue]   If Trim(Me.docPath & "") = "" Then
      Me.CommandButton.Enabled = True
   Else
      If Screen.ActiveControl.Name = "[purple][b]ControlButtonName[/b][/purple]" Then
         [green]'move focus elsewhere[/green]
         Me.[purple][b]TextboxName[/b][/purple].SetFocus
      End If
      
      Me.CommandButton.Enabled = False
   End If[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Good point to put it in the OnCurrent but I think it ought to be called from the textbox LostFocus as well so that the button gets disabled if the user makes an entry. Looks like we need a separate method that's called from both places.

Geoff Franklin
 
alvechurchdata said:
[blue]Looks like we need a separate method that's called from both places.[/blue]
We can accomplish that by wrapping the code in a custom function or sub ...

See Ya! . . . . . .

Be sure to see thread181-473997 [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