I'm trying to create a fairly complex database which includes one to many relationships. After some time learning about Cardbox it appears there's no easy way to do this, anyone have any idea? For example I have a record for a customer and a number of transactions relating to that customer.
Also, is it possible to use a macro to change the list of items in a drop-down list?
The solution to this problem is built-in: relational searches (see manual):
Create two databases: one containing the customers including a unique customer ID and one containing the transactions, including the same unique customer ID.
You can link both databases using this ID. The basic concept of this method is that you open both databases and you search for a certain customer. Cardbox retrieves the customer record and takes the ID (could be any kind of number or word, as long as it is unique to make sure Cardbox links the right records) and it searches for all records having this ID in the transactions database. The result is one window containing the customer data and a second window containg all transactions.
The same could be done vice versa.
This macro is an example of how to open the transactions database from the customer database, assuming:
the databases are "customers" and "transactions"
the server is called "cardbox"
there is a default profile in transactions called "search", without a password
The macro tries to activate "transactions". If it succeeds it does nothing else.
If it fails it opens "transactions", sets up a relational link, tiles both windows and returns to "customers".
This example macro will only work correctly if you always use it to open the transactions database. If you open "transactions" manually, make a selection and then use this macro, no link will be set up.
Of course this macro can be altered to provide for all possible circumstances.
on error resume next
if err.number <> 0 then
if SelectionLevel = 0 then
As far as I know there's no way of changing the format file by means of a macro.
But you say you want to add a new transaction. If you set up two databases, the transactions database will only contain the customer ID. You'd have to select the right customer from a list of (possibly) nondescriptive ID's, which is prone to mistakes.
Why not do as follows:
- Have both databases open (you can use the previously described macro for this).
- Select a customer, or add one if necessary. The Transactions window will show the current transactions.
- Use the macro from the example below. It has to be activated from the Customer database (you are already there) and using a button saying "add transaction" would be a logical thing to do.
The macro takes the customer ID of the current customer (remember you don't copy the entire customer data to the transaction, just the ID), switches to the Transactions database, and adds a new record with the correct ID already filled in.
You could have a "list view" in your Customer database, with just the customer's name and ID on a single line, to serve as your drop-down list. Put the button in the heading and you're done.