RunCode

G

Guest

I can't set the value of a checkbox to be true. I don't know if what I did
is the best or easiest way since I'm not a programmer. I'm trying to learn
so I save my macros as modules to see how it's written. If I did anything
incorrectly please tell me.

I created two macros then did a Save As, Module, and now I have two
functions. One is called CheckBoxCSA. It will set the value of
[ysnEmailedCSA] to true (the default value is set to False in the table).
The other is called EmailCSA. This opens an email form with the email
address in the To: field and the data from two fields on the form in the
message text. This also has the Edit Message property set to "Yes" so I can
add more information if needed.

I have a Command Button (cmdEmailCSA). This button, when clicked, runs the
macro mcrEmailCSA. The macro does RunCode so both functions (CheckBoxCSA and
EmailCSA) run. At least that's what I want it to do but it won't. I had it
do EmailCSA first then CheckBoxCSA. The mail part works. If I switch the
order the mail part still works. The checkbox is empty but something does
happen because if I click for a new record the checkbox has a check mark in
it so the default value was set to True...but that's not the one I want it
on. I want it on the record that was just created and the email sent.
Thanks for the help.~~ Ann
 
S

Steve Schapel

Ann,

Please provide details of the macros you are using, i.e. Actions and
Argument settings.
 
G

Guest

This converted macro puts the check in the box:

Option Compare Database

'------------------------------------------------------------
' mcrCheckBoxCSA
'
'------------------------------------------------------------
Function CheckBoxCSA()
On Error GoTo CheckBoxCSA_Err

Forms!frmLogProblem!ysnEmailedCSA.DefaultValue = -1


CheckBoxCSA_Exit:
Exit Function

CheckBoxCSA_Err:
MsgBox Error$
Resume CheckBoxCSA_Exit

End Function


This converted macro sends the email:

Option Compare Database


'------------------------------------------------------------
' EmailCSA
'
'------------------------------------------------------------
Function EmailCSA()
On Error GoTo EmailCSA_Err

With CodeContextObject
DoCmd.SendObject , "", "", "(e-mail address removed)", "", "",
"Problem Logged", _
"Problem logged: " & .memProblem & vbCrLf & vbCrLf & "Path to
documentation if available: " _
& vbCrLf & vbCrLf & .hlkDocumentation, True, ""
End With

EmailCSA_Exit:
Exit Function

EmailCSA_Err:
MsgBox Error$
Resume EmailCSA_Exit

End Function


The macro on the button that runs when the button is clicked is called
mcrEmailCSA and there are two Actions. The first is RunCode and it's
Function Name is CheckBoxCSA(). The second RunCode has a Function Name of
EmailCSA(). This is where I tried switching which one runs first but the
only one that runs is the email function. Thanks.

Steve Schapel said:
Ann,

Please provide details of the macros you are using, i.e. Actions and
Argument settings.

--
Steve Schapel, Microsoft Access MVP

I can't set the value of a checkbox to be true. I don't know if what I did
is the best or easiest way since I'm not a programmer. I'm trying to learn
so I save my macros as modules to see how it's written. If I did anything
incorrectly please tell me.

I created two macros then did a Save As, Module, and now I have two
functions. One is called CheckBoxCSA. It will set the value of
[ysnEmailedCSA] to true (the default value is set to False in the table).
The other is called EmailCSA. This opens an email form with the email
address in the To: field and the data from two fields on the form in the
message text. This also has the Edit Message property set to "Yes" so I can
add more information if needed.

I have a Command Button (cmdEmailCSA). This button, when clicked, runs the
macro mcrEmailCSA. The macro does RunCode so both functions (CheckBoxCSA and
EmailCSA) run. At least that's what I want it to do but it won't. I had it
do EmailCSA first then CheckBoxCSA. The mail part works. If I switch the
order the mail part still works. The checkbox is empty but something does
happen because if I click for a new record the checkbox has a check mark in
it so the default value was set to True...but that's not the one I want it
on. I want it on the record that was just created and the email sent.
Thanks for the help.~~ Ann
 
S

Steve Schapel

Ann,

I would advise against trying to mix and match macros and VBA
procedures. Why don't you just use a macro with 2 actions, and forget
the VBA? Or else a simple VBA procedure to do the whole thing?

By the way, Access does have an option to convert macros to VBA, but in
practice the resultant VBA is very awkward and difficult to read, and at
best it just won't work at all in the case of complex macros.

I don't fully understand the EmailCSA() function. The only odd thing I
can see in CheckBoxCSA is that it is trying to modify the DefaultValue
property. The Default Value of a control is only applicable at the
point where a new record is being created, so this will not "put the
check in the box". If you wanted to use a macro to "put the check in
the box" in an existing record, you would use a SetValue action, with
the arguments set like this...
Item: [ysnEmailedCSA]
Expression: -1
 
G

Guest

Thanks for the help. I started out doing two macros but the one that sends
the email kept truncating the message text at 255 characters. It's a memo
field so there was a lot more information that needed to be sent. At that
point I found instructions at the community website on how to do the Save
As... to convert a macro to a module. That worked fine and all of the
information was in the message.

Then I wanted to do the checkbox. I tried a macro but it wouldn't run when
there was a RunCode (to run a function) as one of the actions with the
SetValue. Again I found information on the website not to mix them so that
is how everything got converted. I didn't think I would have a problem if a
macro did two RunCode actions(one to check the box and the other to send the
email).

I know that the Default Value only does that at record creation but I didn't
know if you needed to know that or not...it was just information.

The macro that was converted did use the SetValue to put the check in the
box but that's when it wouldn't do it along with the other function.

The only way it worked is if it was on it's own button but then it's the
same as clicking the check box yourself. When they do that they are
forgetting to click the button to send the email.

I know it's really hard to get all the information expressed properly. I
don't know how I'll do this but I appreciate the help you've given me. Thank
you.

Steve Schapel said:
Ann,

I would advise against trying to mix and match macros and VBA
procedures. Why don't you just use a macro with 2 actions, and forget
the VBA? Or else a simple VBA procedure to do the whole thing?

By the way, Access does have an option to convert macros to VBA, but in
practice the resultant VBA is very awkward and difficult to read, and at
best it just won't work at all in the case of complex macros.

I don't fully understand the EmailCSA() function. The only odd thing I
can see in CheckBoxCSA is that it is trying to modify the DefaultValue
property. The Default Value of a control is only applicable at the
point where a new record is being created, so this will not "put the
check in the box". If you wanted to use a macro to "put the check in
the box" in an existing record, you would use a SetValue action, with
the arguments set like this...
Item: [ysnEmailedCSA]
Expression: -1

--
Steve Schapel, Microsoft Access MVP

This converted macro puts the check in the box:

Option Compare Database

'------------------------------------------------------------
' mcrCheckBoxCSA
'
'------------------------------------------------------------
Function CheckBoxCSA()
On Error GoTo CheckBoxCSA_Err

Forms!frmLogProblem!ysnEmailedCSA.DefaultValue = -1


CheckBoxCSA_Exit:
Exit Function

CheckBoxCSA_Err:
MsgBox Error$
Resume CheckBoxCSA_Exit

End Function


This converted macro sends the email:

Option Compare Database


'------------------------------------------------------------
' EmailCSA
'
'------------------------------------------------------------
Function EmailCSA()
On Error GoTo EmailCSA_Err

With CodeContextObject
DoCmd.SendObject , "", "", "(e-mail address removed)", "", "",
"Problem Logged", _
"Problem logged: " & .memProblem & vbCrLf & vbCrLf & "Path to
documentation if available: " _
& vbCrLf & vbCrLf & .hlkDocumentation, True, ""
End With

EmailCSA_Exit:
Exit Function

EmailCSA_Err:
MsgBox Error$
Resume EmailCSA_Exit

End Function


The macro on the button that runs when the button is clicked is called
mcrEmailCSA and there are two Actions. The first is RunCode and it's
Function Name is CheckBoxCSA(). The second RunCode has a Function Name of
EmailCSA(). This is where I tried switching which one runs first but the
only one that runs is the email function. Thanks.
 
S

Steve Schapel

Ann,

I know of no reason for the memo data to be truncated when using a
SendObject macro. Also, it is simply not correct that you can't use a
RunCode action and a SetValue action in the same macro. Similarly,
there is no reason not to have two RunCode actions in the same macro. I
don't know what the problem could be, since you didn't give any
information about thE macros. Nor can I really advise specifically
about what to do, because I don't know where this macro/code is supposed
to run from, and what Event. If you want to use VBA, then get rid of
these functions, and just write the procedure directly into the place it
will run from. All you will need is like this...

DoCmd.SendObject acSendNoObject, , , "(e-mail address removed)", , ,
"Problem Logged", "Problem logged: " & Me.memProblem & vbCrLf & vbCrLf
& "Path to documentation if available: " & vbCrLf & vbCrLf &
Me.hlkDocumentation
Me.ysnEmailedCSA = -1
 
G

Guest

I think maybe this has gotten too confusing and frustrating for both of us.
The code you gave me is the code I listed in my second reply (that Access
converted for me) and I did give you the macro also in my second reply.
There is only one and it does two "RunCodes". One for the email and one for
the checkbox but only one of them will work...the one that has to do with
sending the email. I do appreciate the help you've given me but I will look
elsewhere.

Also, I have come across several questions on this site with the truncating
probelm.
 
S

Steve Schapel

Ann,

Sorry for the confusion. I thought I already told you why it wasn't
working... the code is relating to the DefaultValue property of the
checkbox, rather than changing its value as you seem to want.
 

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