Help! - Disabling Command Buttons

W

wilsy

Hi all,

Apologies in advance if this is something simple, I am a complete newbie to
Access (3 days!). I need to disable four command buttons on a subform (not
continuous) depending on the selection of a combo box. I have the code below
'on current' (form) and 'on update' for the combo.

Each command button's function is to preview a report, which is based on a
query. The command buttons are disabling just fine but fail to function when
multiple records exist. No error is produced, but the report simply does not
preview.

I have spent hours trawling through the forums and I am certain the answer
already exists, its just that I cant find it )-:

Thanks in anticipation,

Rick.

If Me.[Intervention Type] = "Verbal" Then
Me.[verb let].Enabled = True
Else
Me.[verb let].Enabled = False
End If
If Me.[Intervention Type] = "ABC" Then
Me.[abc letter].Enabled = True
Else
Me.[abc letter].Enabled = False
End If
If Me.[Intervention Type] = "ABC" Then
Me.[abc].Enabled = True
Else
Me.[abc].Enabled = False
End If
If Me.[Intervention Type] = "Exclusion" Then
Me.[exc let].Enabled = True
Else
Me.[exc let].Enabled = False
End If
 
D

Douglas J. Steele

If the command buttons are enabled, and they're not doing anything when
pressed, is the code in the Click event for the buttons?

If there is, is it firing?

If not, double-check under Properties for each button that there's something
associated with the Click event.
 
W

wilsy

Hi Douglas,

Many thanks for the swift reply.

Tes, the buttons performed perfectly until I applied the code to hide them.
The code I have for one of the buttons for the click event is as below (I
wont paste the code for all four buttons): -

Private Sub verb_let_Click()
On Error GoTo Err_verb_let_Click

Dim stDocName As String

stDocName = "Verbal Letter"
DoCmd.OpenReport stDocName, acPreview

Exit_verb_let_Click:
Exit Sub

Err_verb_let_Click:
MsgBox Err.Description
Resume Exit_verb_let_Click

End Sub

Regards,

Rick.
 
D

Douglas J. Steele

So as I asked before, is the procedure firing? (Put a MsgBox inside it)

If not, double-check under Properties for each button that it says [Event
Procedure] as the property for the Click event.
 
W

wilsy via AccessMonster.com

Hi Douglas,

Many apologies, as I said I'm a little new to this.

The code is there, there is an event procedure in place for each button (on
click), but sometimes they launch the report and sometimes they are not
launching the report. When they dont launch the report they just seem to be
refreshing the form.

Thanks for your help.

Regards,

Rick.
So as I asked before, is the procedure firing? (Put a MsgBox inside it)

If not, double-check under Properties for each button that it says [Event
Procedure] as the property for the Click event.
Hi Douglas,
[quoted text clipped - 25 lines]
 
D

Douglas J. Steele

What happened when you put a message box into the code, as I suggested. Did
it fire?

Select one of the buttons that isn't working and look at the Properties
page. For the Click event of the button, is the property set to [Event
Procedure]? If not, set it.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


wilsy via AccessMonster.com said:
Hi Douglas,

Many apologies, as I said I'm a little new to this.

The code is there, there is an event procedure in place for each button
(on
click), but sometimes they launch the report and sometimes they are not
launching the report. When they dont launch the report they just seem to
be
refreshing the form.

Thanks for your help.

Regards,

Rick.
So as I asked before, is the procedure firing? (Put a MsgBox inside it)

If not, double-check under Properties for each button that it says [Event
Procedure] as the property for the Click event.
Hi Douglas,
[quoted text clipped - 25 lines]
 
W

wilsy via AccessMonster.com

Hi Douglas,

Yes, it fired ok, it just didnt preview the report?

Regards,

Rick.
 
D

Douglas J. Steele

Okay, then I'm afraid I'm out of ideas. Try putting a breakpoint in the sub.
Click on the margin to the left of the

stDocName = "Verbal Letter"

line so that a brown dot appears in the margin, and the line is highlighted.
Start your form normally. When you click on the button, you should be taken
into the code at that point. Use F8 to move sequentially through the code,
making sure the OpenReport line is executed.
 
W

wilsy via AccessMonster.com

Hi Douglas,

Many thanks for your time, it's really appreciated.

This one has me confused too. The buttons work fine before the code is
applied and the reports are previewed perfectly well. Once the code is
applied they start to behave very unpredictably. Strangley the abc cmd button
always seems to execute perfectly normally!

Thanks once again, this is such a friendly place (c:

Regards,

Rick.
 
W

wilsy via AccessMonster.com

Good morning!

This is now sorted, the code was good in the first instance. What had
happened was that the margins had somehow been reset for the reports making
them return an error. The error wasnt displayed when calling them from the
command buttons.

I'm so relieved I can now carry on with my weekend!!

Thanks for your help and advice Douglas, its really appreciated.

Regards,

Rick.
 

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

Top