View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default Using Excel as a Database

FWIW, I use a text file as a db. Saving is pretty much instantaneous. For
data retrieval, it can populate 150 rows or so before the user form that
calls it has time to close. This is roughly an order of magnitude faster than
Excel. I wrote this a while back for a project used at work. Don't have the
code and don't remember it well. It was quite specialized for my situation
though.

In general (from memory) it involved the following.

Saving:
1. Define a unique identifier (UI) for each record (date in my case).
2. Define the source cell range (noncontiguous in my case).
3. First equate a text var to the UI.
4. Loop through the text file looking for the UI to see if it already exists.
5. If found, record the file location and querry if should overwrite. Abort
if overwrite refused.
6. Now loop through the cell range concatenating the cell values to the
same text var using a semi-colon delimiter.
7. If UI was not found (step 5) then append the concatenated record to the
file else overwrite the location where found. An entire record goes into one
line in the text file.

Retrieving:
1. Loop through the records in the text file and append the UI's to an
array. Use the InStr function to discriminate the UI from the concatenated
string during the search. Then populate a combo box in a user form with the
array. Example (where arr is an array of UI's from the text file):
Load UserForm1
UserForm1.ListBox1.List = arr
UserForm1.Show

2. User selects a record using the combo box.
3. Use the combo box listindex as an offset or loop through the file again
looing for the record.
4. Retrieve the concatenated record.
5. Use the Split function to quickly create an array of the values.
6. Loop through the cell range and populate the values.
7. I also designed a record deletion option.

To research working with text files, see VBA's Open statement.

Regards,
Greg