Conditional Command Button

calmwind

Registered User.
Local time
Today, 01:10
Joined
Oct 12, 2004
Messages
29
I am trying to disable or enabled a command button (cmdPreviewSingleReport) depending on if the word "Adjunct" is in the txtTitle.

Any help would be appreciated.

Private Sub cmdPreviewSingleReport_Click()
On Error GoTo Err_cmdPreviewSingleReport_Click

If Not txtTitle = "Adjunct" Then

cmdPreviewSingleReport.Enabled = False

Else

DoCmd.RunCommand acCmdSaveRecord

Dim stDocName As String

stDocName = "rptAdjunctContract"

DoCmd.OpenReport "rptAdjunctContract", acPreview _
, , "[SSN]= forms!frmContract![SSN]"

End If

Exit_cmdPreviewSingleReport_Click:
Exit Sub

Err_cmdPreviewSingleReport_Click:
MsgBox Err.Description

Resume Exit_cmdPreviewSingleReport_Click


End Sub
 
Code:
Private Sub Form_Current()
    Me.cmdPreviewSingleReport.Enabled = Me.txtTitle = "Adjunct"
End Sub
 
You've got the enable/disable code in the wrong place/basically you are asking the command button to disable itself.

The above is correctly placed in the OnCurrent Event.
 
Thank you both for your help.

When I tried to use

Code:
Private Sub Form_Current()
Me.cmdPreviewSingleReport.Enabled = Me.txtTitle = "Adjunct"
End Sub

it gave me a error:
Run-time error'94': Invalid use of Null

But now knowing where to put some code, this worked out quite nicely.

Private Sub Form_Current()

If txtTitle = "Adjunct" Then

Me.cmdPreviewSingleReport.Enabled = True

Else

Me.cmdPreviewSingleReport.Enabled = False

End If

End Sub

Again, that you so much.
 

Users who are viewing this thread

Back
Top Bottom