Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Help with MACRO"

Help with MACRO

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

Posted By Post

SHopkin

10-Nov-2009 12:36

We have a file which we use to keep all our customers contacts listed so we frequently have several records for one company (as we have multiple contacts for each company) I have tried to create a macro which selects all the contacts for one company in one go eg: If we are looking at a record for Joe Bloggs at British Midland it will find all the contacts for British Midland

I have tried :
EditRecord
Command cmdSelectAll
Command cmdCopy
DoNotSaveRecord
SelectionLevel=0
ActiveWindow.Select "COMPANYNAME","""BRITISH MIDLAND MAINTENANCE HANGER"""

But this unfortunately keeps pasting the same Company name into the macro. This example also would be better to just select on the first two words of a company name ie British Midland

Any help gratefully received

bert

10-Nov-2009 17:14

Try this:

x = Fields("COMPANYNAME")
SelectionLevel=0
ActiveWindow.Select "COMPANYNAME","""" & x & """""

You can also make the selection into a new window:
x = Fields("COMPANYNAME")
OpenFile database
ActiveWindow.Select "COMPANYNAME","""" & x & """""

Success
Bert

SHopkin

10-Nov-2009 17:57

Thank you Bert. Is there any way of just selecting & using the first two words in the field (hence eliminating variations such as Ltd & Limited)

bert

10-Nov-2009 18:44

x = Fields("COMPANYNAME") & " " 'COMPANYNAME + two spaces in case there is only one word
y = split(x," ") 'place all terms in an array - you need first two for selection
                                   'you got them because the added spaces
SelectionLevel=0
ActiveWindow.Select "COMPANYNAME","""" & y(0) & " " & y(1) & """" 'use first two term of the array.

Have attention: this macro does not support punctuation in a name!
If you want to support punctuation it is better to use SelectData command. Use right parameters - look in the Cardbox Help for it. This is a little slower, but I think fast enough.

regards
bert

SHopkin

11-Nov-2009 11:33

Bert - you are a superstar ! You've enabled us to make a huge bound in enhancing the value we get out of Cardbox ! If you are ever looking for paid consultancy I would like to talk further.

Kind regards,
Samantha

Quick Reply

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

 
© 2010 Cardbox Software Limited   Home