VB help with True/False Check box

D

dsc2bjn

I would like to write some VB code which will run two different macros.

If the Check box is NOT check, I want it to run one macro.
If the Check box is checked, I want the macro to run a different one.

I tried using the AfterUpdate and creating the following:

Private Sub CAMO_Concurrence_AfterUpdate(Cancel As Integer)

If CAMO_Concurrence = "True" Then DoCmd.RunMacro "macSAR_Weakness_(Closed)"
If CAMO_Concurrence = "False" Then DoCmd.RunMacro "macSAR_Weakness_(Open)"

End Sub

I get a message stating in part..."Procedure declaration does not match
description of event or procedure having the same name.

How can I do this?
 
F

fredg

I would like to write some VB code which will run two different macros.

If the Check box is NOT check, I want it to run one macro.
If the Check box is checked, I want the macro to run a different one.

I tried using the AfterUpdate and creating the following:

Private Sub CAMO_Concurrence_AfterUpdate(Cancel As Integer)

If CAMO_Concurrence = "True" Then DoCmd.RunMacro "macSAR_Weakness_(Closed)"
If CAMO_Concurrence = "False" Then DoCmd.RunMacro "macSAR_Weakness_(Open)"

End Sub

I get a message stating in part..."Procedure declaration does not match
description of event or procedure having the same name.

How can I do this?

Check box values are numbers, (-1 for True, 0 for False) not text
"True" "False", so using your method it would read:

Private Sub CAMO_Concurrence_AfterUpdate(Cancel As Integer)

If CAMO_Concurrence = True Then DoCmd.RunMacro
"macSAR_Weakness_(Closed)"
If CAMO_Concurrence = False Then DoCmd.RunMacro
"macSAR_Weakness_(Open)"

End Sub

However, since a check box is either True or False, you can condense
the above code (and make it easier logically to read and understand):

If CAMO_Concurrence = True Then
DoCmd.RunMacro "macSAR_Weakness_(Closed)"
Else
DoCmd.RunMacro "macSAR_Weakness_(Open)"
End if
 
J

Jon Lewis

Whilst what fredg has said is true, the reason for your error message is
that the after update event does not have a Cancel argument so the correct
syntax for the procedure is:

Private Sub CAMO_Concurrence_AfterUpdate( )

HTH
 
D

dsc2bjn

Thanks!!!

That works fine.

I have decided to make the check at the form submission (Close action),
since I need both tables populated at the time the form is closed.

My thought would be to have it check to see if the record already exists in
the "Open" table and just update it. Since the "closed" records will not be
on the pick list they won't be a problem as I can append the newly closed
records to the end of the "Closed" table.

Any suggestion on how to do this (code) would be most appreciated.
 

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