Help enable/disable command button

  • Thread starter Thread starter mdavis via AccessMonster.com
  • Start date Start date
M

mdavis via AccessMonster.com

I have the following code in a list box's After Update event and on the forms
On Current event.

If IsNull(Listbox) Or Listbox = "" Then
AddButtonMotif.Enabled = True
EditButtonMotif.Enabled = False
Else
AddButtonMotif.Enabled = False
EditButtonMotif.Enabled = True
End If

The list box is based on a query and is unbound. What I want to happen is if
there is not a value in the Listbox I would like the Add button to be enabled.

Then the user can click and a pop up form will open for them to enter a new
value. After they enter the new value and return to the main form I would
like the Add button to be disabled and the Edit button to be enabled. When
the user clicks the Edit button and the pop up form opens and the user
decides to delete the value and then they return to the main form I would
like the Add Button enabled again and the Edit button disabled.

For some reason this doesn't want to work. If I have a value
in the Listbox the Add button is still enabled and the Edit button is
disabled.

Thank you in advance.
 
Try:
If Me.ListBox.ListCount = 0 Then
I have the following code in a list box's After Update event and on the forms
On Current event.

If IsNull(Listbox) Or Listbox = "" Then
AddButtonMotif.Enabled = True
EditButtonMotif.Enabled = False
Else
AddButtonMotif.Enabled = False
EditButtonMotif.Enabled = True
End If

The list box is based on a query and is unbound. What I want to happen is if
there is not a value in the Listbox I would like the Add button to be enabled.

Then the user can click and a pop up form will open for them to enter a new
value. After they enter the new value and return to the main form I would
like the Add button to be disabled and the Edit button to be enabled. When
the user clicks the Edit button and the pop up form opens and the user
decides to delete the value and then they return to the main form I would
like the Add Button enabled again and the Edit button disabled.

For some reason this doesn't want to work. If I have a value
in the Listbox the Add button is still enabled and the Edit button is
disabled.

Thank you in advance.
 
Thank you very much. The only thing that doesn't work is when I click on the
Edit command button which opens up a pop up form and I delete the record.
When I go back to the main form the Edit command button is still enabled and
the Add command button is disabled. Any ideas?
Try:
If Me.ListBox.ListCount = 0 Then
I have the following code in a list box's After Update event and on the forms
On Current event.
[quoted text clipped - 22 lines]
Thank you in advance.
 
Open your PopUp in acDialog mode and then call the code again in the line
after the OpenForm. You *did* create a separate SubRoutine for this right?
You now have three places where it is used.
Thank you very much. The only thing that doesn't work is when I click on the
Edit command button which opens up a pop up form and I delete the record.
When I go back to the main form the Edit command button is still enabled and
the Add command button is disabled. Any ideas?
Try:
If Me.ListBox.ListCount = 0 Then
[quoted text clipped - 4 lines]
 
This is what I have and it doesn't seem to work.

Private Sub AddButtonMotif_Click()

DoCmd.OpenForm "FrmMotifSpec", , , , acFormAdd, acDialog
If Me.List3.ListCount = 0 Then
AddButtonMotif.Enabled = True
EditButtonMotif.Enabled = False
Else
AddButtonMotif.Enabled = False
EditButtonMotif.Enabled = True
Response = acDataErrAdded

End If
Me.List3.Requery



End Sub
Open your PopUp in acDialog mode and then call the code again in the line
after the OpenForm. You *did* create a separate SubRoutine for this right?
You now have three places where it is used.
Thank you very much. The only thing that doesn't work is when I click on the
Edit command button which opens up a pop up form and I delete the record.
[quoted text clipped - 6 lines]
 
You need to Requery the ListBox *before* you test the ListCount!
This is what I have and it doesn't seem to work.

Private Sub AddButtonMotif_Click()

DoCmd.OpenForm "FrmMotifSpec", , , , acFormAdd, acDialog
If Me.List3.ListCount = 0 Then
AddButtonMotif.Enabled = True
EditButtonMotif.Enabled = False
Else
AddButtonMotif.Enabled = False
EditButtonMotif.Enabled = True
Response = acDataErrAdded

End If
Me.List3.Requery


End Sub
Open your PopUp in acDialog mode and then call the code again in the line
after the OpenForm. You *did* create a separate SubRoutine for this right?
[quoted text clipped - 5 lines]
 
That worked great but when I click the Edit command button and the pop up
form opens and I delete the record and click the Close button to return to
the main form the Edit command button is still enabled and the Add command
button is disabled. I was thinking that I might have to put some code in the
Close command button of the pop up form?

Here is the code I have for the Close button.

Private Sub CloseFrm_Click()
On Error GoTo Err_CloseFrm_Click

DoCmd.Close

Exit_CloseFrm_Click:
Exit Sub

Err_CloseFrm_Click:
MsgBox Err.Description
Resume Exit_CloseFrm_Click

End Sub
You need to Requery the ListBox *before* you test the ListCount!
This is what I have and it doesn't seem to work.
[quoted text clipped - 20 lines]
 
You can't disable the control with the focus! Move the focus to another
control for your test. You should have been getting an error.
That worked great but when I click the Edit command button and the pop up
form opens and I delete the record and click the Close button to return to
the main form the Edit command button is still enabled and the Add command
button is disabled. I was thinking that I might have to put some code in the
Close command button of the pop up form?

Here is the code I have for the Close button.

Private Sub CloseFrm_Click()
On Error GoTo Err_CloseFrm_Click

DoCmd.Close

Exit_CloseFrm_Click:
Exit Sub

Err_CloseFrm_Click:
MsgBox Err.Description
Resume Exit_CloseFrm_Click

End Sub
You need to Requery the ListBox *before* you test the ListCount!
[quoted text clipped - 3 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top