Home

Macros and Programming

 

CardboxForumsMacros and Programming > "macro to change state of checkbox"

macro to change state of checkbox

Current user: [none]
Register / Log In · Help

Posted By Post

TB

20-Aug-2011 11:36

Hi,

I made a macro (activated by a pushbutton) to check an item in a checkbox. looks like this:

EditRecord
GoToField "GROUPE"
SetOption 0,True
SaveRecord

Reason: faster, no double click and ctrl S, just click the button...

However: to deactivate the item, i must make a second button:

EditRecord
GoToField "GROUPE"
SetOption 0,False
SaveRecord

What is the command to change the state from False to True, and from True to False with only one macro?
If SetOption 0,False then SetOption 0,True does not work.

Thanks.

Tim

bert

20-Aug-2011 12:41

As far as I know you cannot read the state a checkbox item.
However, you can read a field content. And a checkbox does nothing more or less that add/remove the connected term in a field.

So:
A macro example for this toggle:
Change in macro below TERM for the word that is connected with your checkbox item.

'make object of current record
Set arec = ActiveRecord
  
'read content field groupe
x = arec.Fields("GROUPE")

arec.edit
if instr(x,"TERM") > 0 then
   'if term is present then save everything in the field
   'but remove TERM + remove unwanted leading spaces
   arec.Fields("GROUPE") = trim(replace(x,"TERM",""))
else
   'if term is not present - add it!
    arec.Fields("GROUPE") = "TERM" & " " & x 'add term in existing content of field group
end if
arec.save

I hope it works.
Success
Bert

TB

20-Aug-2011 13:11

Makes it a bit longer, but works fine ! Thanks for the incredibly fast answer, Bert !

Tim

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home