Set Command Button Not to Work Unless Certain Fields Contain Data (1 Viewer)

Mick3911

Registered User.
Local time
Today, 02:20
Joined
Jul 31, 2018
Messages
40
I have a form where there is a Command Button to e-mail a report.
What I would like to happen is that the Command Button will not function unless the Investigation and Root Cause fields on the form have had data entered into them.

Command Button is named: View/Send Report
First field that I want to have data in is named: Investigation Findings
Second field that I want to have data in is named: Root Cause

Is this possible, if it is how do I go about doing it?

I’m guessing that it can be done by VBA but my VBA knowledge is not that great.

Many thanks
 

CJ_London

Super Moderator
Staff member
Local time
Today, 02:20
Joined
Feb 19, 2013
Messages
16,629
it is not a good idea to have spaces in names as VBA will not recognise them and will either fail or substitute an underscore . Similarly none alpha numeric characters can cause issues- so in my example I have removed them. You will need to put them back if required

in the form create a sub called say disableButton

Code:
Sub disableButton()
 
    ViewSendReport.enabled=not (isnull(InvestigationFindings) and isnull(RootCause))
 
End Sub
then in your form current and the after update events for the InvestigationFindings and RootCause controls just put

Code:
disableButton
 

Mick3911

Registered User.
Local time
Today, 02:20
Joined
Jul 31, 2018
Messages
40
Hi CJ_London

Thanks for your reply.

How do you mean create a sub in the form?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 02:20
Joined
Feb 19, 2013
Messages
16,629
open form in design view
open properties
on the dropdown, select form
click on the events tab
on the current event, click the carat to the right and choose code

that will get you into the vba editor at the right place for the form current event
 

Users who are viewing this thread

Top Bottom