View Full Version : Disabled Button Help?


alferr
05-19-2002, 10:54 PM
I need some help... i need to know how to disable a button in a form from another form!! i.e. you click a button in one form which disables a button in the second form!! ok thanks for your help


al

DJN
05-20-2002, 03:06 AM
In the code for the command button that opens the second form, add another line after the line that opens the form.

On Error GoTo Err_cmdOpenForm_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FormToBeOpened"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!FormToBeOpened!CommandButtonName.Enabled = False
Exit_cmdOpenForm_Click:
Exit Sub

Err_cmdOpenForm_Click:
MsgBox Err.Description
Resume Exit_cmdOpenForm_Click

ColinEssex
05-20-2002, 03:16 AM
I'm intrigued as to why you would want to disable a button on form 2 from form 1.

Can you not set the button to enabled = false OnOpen of the second form?

Col

Rich
05-20-2002, 04:11 AM
The second form may open on it's own for data entry without form1 controling some event maybe.

alferr
05-20-2002, 08:29 PM
thanks DJN

but when i do this it comes up with a message

"You can't disable a control while it has focus"

please help thanks

Fornatian
05-20-2002, 11:26 PM
Set the focus to another field using:

Forms("FormName").ControlName.SetFocus

after:

Forms!FormToBeOpened!CommandButtonName.Enabled = False

or change the tab order of the second form because it appears that the button is the first control on the form to receive the focus.