CraigDolphin
GrumpyOldMan in Training
- Local time
- Today, 09:27
- Joined
- Dec 21, 2005
- Messages
- 1,582
I have been tasked with coming up with a way to automate reconciliation of fish-ticket data in two databases. One database is administered by WA State Dept. Fish & Wildlife (no ability to access this myself) and the other by my employer (Lummi Nation). Both databases should contain identical information (yeah right) since each organisation gets duplicate copies of fish tickets produced by wholesale buyers whenever they buy fish/shellfish.
I can get a summary table in excel from both databases. I have imported them into access as tables, and done select queries to sort the records in ascending order by fish "ticket number" and then by date, species, weight landed, etc.
Each fish ticket number may have more than on record in the table (e.g., a fisherman might catch 200lbs of Chinook and 100 lbs of Coho salmon and both are reported on the same fish ticket.
So, there are three problems I need to be looking for in each table: 1-tickets that are recorded in one db but not the other, 2-records from a ticket that have no matching record in the other database (eg., 4 records in the tribal db and 5 records in the state db for the same ticket number), and 3-when parallel records do exist, are there any significant discrepancies in the recorded amounts of some of the fields for that record?
The tables are quite large (~14,500 records for one year of data) and need to be reconciled reasonably frequently during fisheries to avoid going over quota. The scope and time-consuming nature of this task if done manually has meant that, in practise, no reconciliation has been attempted in 4 years!
I have had a crack at using vba to do this task but without much success. One approach I tried weemed to be working on some sample tables (~300 records) but at about halfway through the process it kept coming up with a no current record error that I couldn't track down. I think it was a result of too much recursive activity between the functions.
I redesigned my vba approach to try to do more with do loops rather than calling functions but now I'm stuck in a loop and was wondering if someone might help me spot my problem?
What I am trying to do with this script is:
make 2 recordsets based on the ordered queries of the state and tribal tables
start at the beginning of each recordset
check the current ticket number against a table of unpaired ticket numbers (built from queries beforehand)
if they do not appear then we can exclude error type 1 and compare the actual ticket numbers.
if the numbers do not match, then we likely have an error of type 2. The record with the lower ticket number has to be exported to a table, and we move to the next record in that recordset and restart the pairwise comparison of ticket numbers.
If the ticket numbers do match, then we compare the data in each field for a type 3 error. If all is the same then we move on to the next record in each recordset and start over. If not, then we export the disagreeing records to suitable tables, and move to the next record in each recordset and start the comparison over again.
If we come to the end of a recordset, then the remaining records in the other trecordset (if any) are to be exported to the appropriate table.
I've attached a copy of the db. The code is linked to a command button on a form that should open at startup. The db is in Access 2000 format. I've tried to comment the code to explain what I'm trying to do.
So, after that long-winded explanation, I'd greatly appreciate any help that may be offered. I'm relatively new to vba and doubtless am making some error(s) that I just can't see.
I can get a summary table in excel from both databases. I have imported them into access as tables, and done select queries to sort the records in ascending order by fish "ticket number" and then by date, species, weight landed, etc.
Each fish ticket number may have more than on record in the table (e.g., a fisherman might catch 200lbs of Chinook and 100 lbs of Coho salmon and both are reported on the same fish ticket.
So, there are three problems I need to be looking for in each table: 1-tickets that are recorded in one db but not the other, 2-records from a ticket that have no matching record in the other database (eg., 4 records in the tribal db and 5 records in the state db for the same ticket number), and 3-when parallel records do exist, are there any significant discrepancies in the recorded amounts of some of the fields for that record?
The tables are quite large (~14,500 records for one year of data) and need to be reconciled reasonably frequently during fisheries to avoid going over quota. The scope and time-consuming nature of this task if done manually has meant that, in practise, no reconciliation has been attempted in 4 years!
I have had a crack at using vba to do this task but without much success. One approach I tried weemed to be working on some sample tables (~300 records) but at about halfway through the process it kept coming up with a no current record error that I couldn't track down. I think it was a result of too much recursive activity between the functions.
I redesigned my vba approach to try to do more with do loops rather than calling functions but now I'm stuck in a loop and was wondering if someone might help me spot my problem?
What I am trying to do with this script is:
make 2 recordsets based on the ordered queries of the state and tribal tables
start at the beginning of each recordset
check the current ticket number against a table of unpaired ticket numbers (built from queries beforehand)
if they do not appear then we can exclude error type 1 and compare the actual ticket numbers.
if the numbers do not match, then we likely have an error of type 2. The record with the lower ticket number has to be exported to a table, and we move to the next record in that recordset and restart the pairwise comparison of ticket numbers.
If the ticket numbers do match, then we compare the data in each field for a type 3 error. If all is the same then we move on to the next record in each recordset and start over. If not, then we export the disagreeing records to suitable tables, and move to the next record in each recordset and start the comparison over again.
If we come to the end of a recordset, then the remaining records in the other trecordset (if any) are to be exported to the appropriate table.
I've attached a copy of the db. The code is linked to a command button on a form that should open at startup. The db is in Access 2000 format. I've tried to comment the code to explain what I'm trying to do.
So, after that long-winded explanation, I'd greatly appreciate any help that may be offered. I'm relatively new to vba and doubtless am making some error(s) that I just can't see.