This will be a weird one, hopefully someone can help
This will be a weird one, hopefully someone can help
I have set up a field where I use the file: command so that when I input a hyperlink location to a path on our server, we can access a file within our server that is particular to the Cardbox record we are viewing.
Is there a way of telling the field we are using as a hyperlink in Cardbox to replace any spaces automatically with the %20 command?
This is what the link originally looked like, which would not have worked if I had not replaced all the spaces with %20
Example: file:\\Server-alpha\master alpha\Saved maintenance Quotes
I have over 1000 hyperlinks to set up, where I need to replace spaces with %20 so Cardbox can see the full path and open up the server record.
At present I am copying the path location into word and using the Ctrl & F function to replace the space with the %20, then copying and pasting this into the Cardbox field.
Any advice would be appreciated.
You could check the solution given in other posts, but I had a similar problem which Cardboss helped me solve with a hyperlink macro tied to a push-button. I had a structured set of folders (F:\My Documents\consulting\catalog) and sub-folders below containing the source pdf documents. The path to the main catalog folder was contained in a field "P1" and the subsequent part of the path to the source documents (\IFPP\WP.15.pdf)was contained in a field "P2". Thus the main catalog folder and its sub-folders could be moved to another location and the filed "P1" updated by a batch edit. The macro was:
This works fine, and does not require %20 to replace all the spaces in the file path.
The other alternative suggested was to copy the source documents into the Cardbox Image field. I rejected this because a) the input copy process with pdf is slow, and b) I will need the ability to copy text from the source documents - this is possible from the pdf but not from the image (copy only gives you an image and not editable text).
Hope this is useful,
Unless someone comes up with something much smarter, you could try using batch edit as follows:
* load %20 onto the clipboard (enter in any field, highlight and press Ctrl+C - than quit without saving)
This of course will only work for the paths of the same format, i.e. same number of blank spaces
If you have multiple path formats (e.g. I would expect that the file names may have different numbers of words), you will need to execute multiple batch commands each on sets with paths of similar structure, but it sure beats copy/past in word.
Bert's solution works fine in the normal way but does not work with spaces.
If you do want to replace your spaces here is a quick macro:
Be sure to select the records you want to loop through (batch edit) first!!
'Create object "recs"
n = recs.Count ' Count the number of records in recs
' Define i as records 1 to the last number, i.e. each record in turn
For i = 1 to n
Set rec = recs(i) Create object "rec" to equal the current record
The above macro is very useful and can be easily adapted for different situations. You could also add an instruction in the macro to select the records first e.g. using the Pause command (see Cardbox macros manual). Actually, Pause does not seem to be in the Macros and Programming manual, at least not in the index. It can be used instead of the VbScript message box. Pause "Select the records you want to amend" ... It pauses the macro so that you can manually intervene and access the database e.g. to select and tag records.
Another way of writing the above macro would be:
n = Records.Count
For i = 1 to n
It is probably easier to see what is happening here, though it won't run as quickly.
I believe Alpha wants to have his/her spaces automatically replaced not only in existing records, where anything from Batch Edit to macros that loop through a selection will work fine, but also everytime a new record is saved.
Please that for some time you have been able to assign a macro to the Save Record command. This means that every time a record is saved, a macro will run before the record is actually saved.
Fields("LINK")= replace(FIELDS("LINK1")," ","%20")
You can assign any macro to the Save command by:
Editing the format where the macro must run, normally the native format so that the macro will always run.
Click Tools > Toolbar > Editing Records and look for the Save Record button. Change the action from "Save Record" to "Run Macro" and assign the above macro to the button. Both the button and the Save Record menu will run the macro. Don't forget that such macros must contain the SaveRecord command, or your record will not be saved.
Having done so, any space within the field "LINK" will always be automatically replaced by "%20".
For existing records, standard search and replace works perfect, also replacing spaces (I just tested it Mary!)
For new records: you have to add in your record a path and/or location of the files. What can be more simple to do this by using this macro:
In this way you do'nt need a "file:" caption in your field. More: you can add more than one file in that field (one by one).
Btw: Adding your macro to the Cardox save command has to be implemented very careful. It is the best using this option only if you work with special workspaces for separated applications.
I would agree with Bert to be careful assigning a macro to the Cardbox save command. We do use it occasionally and it is very useful. However we build in certain conditions in the macro that it runs.
Just a short reaction to the "on save macro":
As to Bert's suggestion that it should be best used in special workspaces, I'd like to know what his arguments are. I've been using this feature in all my databases since it was added (on my request), and implementing it in the formats of the databases guarantuees that the assigned macro runs only in that database. So, even when a workspace has several databases open, the macro will only run in the database it was assigned to or even only in the format it was assigned to. As safe as the Bank of England (perhaps not the most realistic expression).
You are quite right about being careful and aware of all the implications, regardless of the macro. I was just keeping my response simple.
Thank you for inspiring the "On save" macro. Very useful.
So, in my opinion is it safer to use this part of Cardbox in special dedicated applications in special dedicated workspaces. The standard Cardbox workspace is in my opinion the best as it is... standard.
I never suggested that there should be a single "on save" macro for all databases, or that perfectly working standard commands should be replaced by non-standard ones. I simply advocate the use of the "on save" mechanism because it runs transparently. Users don't see it and they can't stop it. They just see that spaces are replaced by "%20" or by "_". Or they may get messages that if they filled out field A, field B must also contain something etc. etc.
Each and every one of my databases (27 to be exact) has its own "on save" macro, assigned to the native format. These macros vary from just a few lines (mostly to replace and improve standard validation) to extensive macros for an ordering system (sending confirmation e-mails, compute VAT etc.) and even a macro of over 400 lines that maintains a thesaurus. They all work "on save" and in their own databases.
The Save as New button can also have a macro assigned to it, either the same as "on save" or another. You can even make a single macro behave differently depending on whether it works on an existing or on a new record.
The only thing that does not work when the Save button has been redirected is Batch Edit. However, none of my users is allowed Batch Edit because the average user is very likely to bring disaster to the database. When told of the consequences of a rash Batch Edit, every user up to now happily declined his or her right to use it.
"Superusers" however may be granted a way out of the "on save" macro by assigning a special and highly secret keystroke to the internal Save command. Hitting that key instead of CTRL-s (or the button/menu) will activate the save command instead of the macro. Or the "on save" macro may be made part of the non-native formats, whereas the native format is left unchanged. Users that may use the native format may then save a record in the standard way. Thus you can have your profiles dictate who uses what.
Globally speaking: anything that automates a task, however simple, reduces the time that is needed to perform it, and reduces the risk that it goes wrong. Every user who enters data is likely to make mistakes or to be forgetful. It's a real comfort to know that when that user hits "save", a macro checks whatever it can check, corrects whatever it can correct and finally says to the user, in his own language: "Well done Bert, no mistakes!"
Mostly I add functionality visible, transparent. So users can see that they are using this functionality.
I Must thank each and everyone of you who have contributed to this discussion so far, although i am a simpleton when it comes to macro writing, I have no programming background, the arguments and comments posted are fantastic. I am just pleased to see so may knowledgeable people trying to solve a common problem
I was once a simpleton too, with no programming background. Necessity for me was certainly the mother of invention. I first started with the Cardbox macro system and was very pleased with what I achieved over the years. When Cardbox switched to Vbscript I was convinced I would never master it. As a non-programmer I found a lot of VbScript books quite daunting. I found "Learn Microsoft VBScript In a Weekend" by Jerry Lee Ford Jr., Premier Press, ISBN: 1931841705 a great book to get me over my fear. It is a real beginner's book (not for the experts, so ignore criticism from expert programmers). You won't learn it all in a weekend of course and it won't teach you how to use Vbscript with Cardbox, as the examples tend to relate to the web. However, it will teach you the basics in a very unintimidating way. Used in conjunction with the Cardbox macros and programming manual it could bring you a long way if you are interested. Even when I had become fairly accomplished in some areas I found myself going back to it to get started on programming for web pages and file management. Our entire library system is now managed by Cardbox and Vbscript programming. In addition to standard library activities we also use Cardbox to automate many other activities such as updating our intranet pages, or tracking the status of our legislation, all of which would be too labour-intensive to do without using macros. My motto has been "there must be an easier way of doing this!". That is a strong motivation for learning programming.
|© 2010 Cardbox Software Limited|