Home

Macros and Programming

 

CardboxForumsMacros and Programming > "Check if database open, if not then open it, if open then next step"

Check if database open, if not then open it, if open then next step

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

Posted By Post

Nickc108

23-Jul-2010 12:00

How to make the macro check:
- if a database is open,
- then if not open, open it;
- else if open then activate it.

bert

23-Jul-2010 13:11

Hi,

Substitute WINDOW TITLE en PATH+DB by your values.
 
for w = 1 to windows.count
    if instr(lcase(windows.item(w).name), "WINDOW TITLE") > 0 then
       Activate windows.item(w).name
       exit for
    end if
Next
if instr(lcase(name), "WINDOW TITLE") = 0 then OpenFile("PATH+DB")

Regards
Bert

Nickc108

26-Jul-2010 11:36

Thanks, Bert. I substituted my parameters but it still opens a second copy of the database. I want to work with relational databases. I'm in one called "JHTenancies" and want to see if another is opened called, "JHPropertiesToLet". If it's not open, to open it, and if open, then to go onto the next step. What I've got is:

DB = "\\Canterburybk\expan drive\BACK UPS\LATTITUDE 10-07-12\JH Cardbox" &_
               "Server\Data\JHPropertiesToLet.fil"
WT = "JHPropertiesToLet"

for w = 1 to windows.count
    if instr(lcase(windows.item(w).name), WT) > 0 then
       Activate windows.item(w).name
       exit for
    end if
Next
if instr(lcase(name), WT) = 0 then OpenFile(DB)

Nick

Charles Welling

26-Jul-2010 13:49

Have a look at the following lines:

1. if instr(lcase(windows.item(w).name), WT) > 0 then

This turnes all window names into lowercase. These names are then compared to your specified window namem which is NOT lowercase. So the comparison will be as follows:

if instr("jhpropertiestolet", "JHPropertiesToLet") > 0 then

Unless you define your window names in lowercase this will never work.

2. if instr(lcase(name), WT) = 0 then OpenFile(DB)

Even if the comparison would turn out te be true, i.e. a window with the specified name would be found, another window of the same databse would still be openend because this second comparison compares your window name to a variable called "name" which has not been defined. So, the result of this comparison will always be 0 and another window will be opened.

Regards, Charles

bert

26-Jul-2010 15:45

Indeed a upper/lower case problem I think.
Variable WT has to be exact as it appears in the Cardbox Window title.
Regards
Bert

Quick Reply

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

 
© 2010 Cardbox Software Limited   Home