VB code help

petercummins

Registered User.
Local time
Today, 13:56
Joined
Sep 6, 2005
Messages
52
Hello,

Is there a way of changing VB code so that ONLYif a statement is true then the command runs.

This is what I currently have:

If Me.chkDoorChoice = True And Me.cboFrontDoorType = "N/A" Or Me.cboFrontDoorColour = "N/A" Or Me.cboRearDoorType = "N/A" Or Me.cboRearDoorColour = "N/A" Or Me.cboAdditionalDoorType = "N/A" Or Me.cboAdditionalDoorColour = "N/A" Then
DoCmd.RunMacro "mcrPleaseNote"
End If

So the command should only run when chkDoorChoice is true. There are occasions when cbofrontdoortype = "N/A" and chkDoorChoice = False and the macro still runs. I dont want this to happen.

Any ideas peeps?
 
Your macro will run if any of the criteria after the first "or" is matched, irrespective as to what Me.chkDoorChoice says.

You need to rewrite the code

Col
 
Would you set it up like this where I just create separate If statements for each criteria or is there a more efficient way?

If Me.chkDoorChoice = True And Me.cboFrontDoorType = "N/A" then
DoCmd.RunMacro "mcrPleaseNote"
End if

If Me.chkDoorChoice = True And Me.cboFrontDoorColour = "N/A" then
DoCmd.RunMacro "mcrPleaseNote"
End If

Not the best at this sort of thing!
 
Replace

If Me.chkDoorChoice = True And Me.cboFrontDoorType = "N/A" then
DoCmd.RunMacro "mcrPleaseNote"
End if

If Me.chkDoorChoice = True And Me.cboFrontDoorColour = "N/A" then
DoCmd.RunMacro "mcrPleaseNote"
End If

with

If Me.chkDoorChoice = True And (Me.cboFrontDoorType = "N/A" or Me.cboFrontDoorColour = "N/A") then
DoCmd.RunMacro "mcrPleaseNote"
End if
 
Thats great cheers guys.

Allan, can you have more than those two statements inside the brackets though? For example on the door choice check box I will need 6 statements in total.
 

Users who are viewing this thread

Back
Top Bottom