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

AcDialog Question 1

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I have a form with command buttons that pull up other forms in the database. My problem is, i need to Disable a command button on the form thats being open from the command button.

it worked before i added the acDialog command.

this is what i had before

docmd.openform "someform"
forms![formname]![command1].enabled = false

Now since I added the acdialog command in the open form statement i get an error stating it cannot find the form name.
does the acdialog command change the form name?? if so does anyone know what i should put in my second command?

Thanks in advance




DVannoy
A+,Network+,CNA
dvannoy@onyxes.com
 
When you open a form in code with acDialog, your code stops execution until the form is closed. So your line:
forms![formname]![command1].enabled = false
doesn't get executed until "someform" is closed. Here's a way around this. I'm assuming you want need to be able to open the form with the button enabled sometimes and disabled other times. When you want to have the button disabled, do it like this:

DoCmd.OpenForm "someform", acNormal,,,,acDialog, "Disable"

When you don't want the button disabled, just leave off the "Disable". Whatever string you put there will be passed to "someform" when it is opened. Then in the Form_Load event for "someform", add a check for OpenArgs like this:

Sub Form_Load()
If OpenArgs = "Disable" Then
cmdButton.Enabled = False
Else
cmdButton.Enabled = True
End If
End Sub

This won't work if the form is already loaded but hidden. So if you are going to be opening and closing the form more than once, make sure you actually close it like this:
DoCmd.Close acForm, "someform"

not just hide it like this:
Me.Visible = False

If you need to hide the form instead of closing it for some reason, the OpenArgs will still work, but the Form_Load event won't fire when you do the DoCmd.Open so you will have to check it some other way. You could just check the OpenArgs when the command button is clicked, and if OpenArgs = "Disable" then don't do anything. Hope this helped.

Shanti
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top