- Aug 12, 2004
- 106
- 0
- 76
Hello.
I have this access database (actually several of them) that I maintain in order with information exported from the EMR that I manage. For the most part producing reports and statistics is ok. I know my way around access, how to produce basic queries for filters and counts, etc. I know just enough about SQL to read it, and to borrow code fragments and redirect them towards some custom queries, etc. And I took a visual basic class years ago, which I might finally have to use (lol).
Anyway, heres the situation.
I have several tables in this one database, that maintain a lot of data with respect to newborn feedings and various situational and clinical criteria.
The two relevant tables here are the master table, which contains a unique record for each child, including medical record number (the primary key) and a discharge date (and other items not necessary to this particular query). The other table is one that contains a list of every feeding for each child.
So (there are many more fields in each table, but the following are the ones in this query)
Table 1
-MedRecNumber
-Discharge Date
Table 2
-Medrecnumber
-date of feeding
-type of feeding
-primary key (just an autonumber field)
All 4 tables in this database are linked one to many from table 1, with the medical record number being the linked item.
So, I need to produce a query that does the following.
-Pulls up all entries relevant to a given time frame (I got this)
-Finds all entries (ie feedings that occur withing 24 hours of discharge
(essentially I do
Field - [Table1]![newborndischargedate] - [Table2]![Newbornfeedingtime]
Total - Expression
Criteria - <1
And that works.
So I get all the feedings for a given date range, that occur in the last 24 hours of discharge.
Now the final step has me somewhat flummoxed.
The purpose of the query is ultimately to produce a count of "exclusively breastfeeding babies".
Now, the query at this point has a list of all the feedings, by all the babies (given that its for a time range and less than 24 hours, which I won't type anymore).
Each record would have
medrecnumber, feeding time, method of feeding
Basically I run a check on all feedings for a given baby, and if it was never bottlefed, then that would increase the count for exclusively breastfed, by 1.
I remember enough visual basic, to sort of piece my way through this, though as it turns out, I remember more C++, lol and was doing my crappy little code like it was c++, but I am sure that I can work my way through this in VBA, it just might take time.
What I want to know is am I going in the right direction.
Would that VBA code work as intended, ie if I put it in the rightmost query column, or rather call it, would it run its count on the records already sorted and filter by the previous criteria.
And then, from a logical point of view is the following correct in the VBA (not the coding but my methodology)(I know I have to declare variables and set up the function inside a module).
---------------------------------
do
do
if
type of feeding = "bottle"
then
exclusive = "no"
while Medreccurrentnum = Medrecprevnum
if exclusive <> "no"
then exclbf = exclbf +1
exclbf = "yes"
until (condition which means there are no more records to look at)
-----------------
Note I am not sure about the condition for the until part, but I am sure I can figure that out, with some research.
Am I overthinking this problem? Is there some simpler way in access to do this in a query?
I enjoy the challenge of this work (I am switching my degree from biomed/electronics to Healthcare informatics as a result of this job) because it is pushing me into new territories. I know I ultimately have to learn SQL and at least get to an intermediate level with VBA
I have this access database (actually several of them) that I maintain in order with information exported from the EMR that I manage. For the most part producing reports and statistics is ok. I know my way around access, how to produce basic queries for filters and counts, etc. I know just enough about SQL to read it, and to borrow code fragments and redirect them towards some custom queries, etc. And I took a visual basic class years ago, which I might finally have to use (lol).
Anyway, heres the situation.
I have several tables in this one database, that maintain a lot of data with respect to newborn feedings and various situational and clinical criteria.
The two relevant tables here are the master table, which contains a unique record for each child, including medical record number (the primary key) and a discharge date (and other items not necessary to this particular query). The other table is one that contains a list of every feeding for each child.
So (there are many more fields in each table, but the following are the ones in this query)
Table 1
-MedRecNumber
-Discharge Date
Table 2
-Medrecnumber
-date of feeding
-type of feeding
-primary key (just an autonumber field)
All 4 tables in this database are linked one to many from table 1, with the medical record number being the linked item.
So, I need to produce a query that does the following.
-Pulls up all entries relevant to a given time frame (I got this)
-Finds all entries (ie feedings that occur withing 24 hours of discharge
(essentially I do
Field - [Table1]![newborndischargedate] - [Table2]![Newbornfeedingtime]
Total - Expression
Criteria - <1
And that works.
So I get all the feedings for a given date range, that occur in the last 24 hours of discharge.
Now the final step has me somewhat flummoxed.
The purpose of the query is ultimately to produce a count of "exclusively breastfeeding babies".
Now, the query at this point has a list of all the feedings, by all the babies (given that its for a time range and less than 24 hours, which I won't type anymore).
Each record would have
medrecnumber, feeding time, method of feeding
Basically I run a check on all feedings for a given baby, and if it was never bottlefed, then that would increase the count for exclusively breastfed, by 1.
I remember enough visual basic, to sort of piece my way through this, though as it turns out, I remember more C++, lol and was doing my crappy little code like it was c++, but I am sure that I can work my way through this in VBA, it just might take time.
What I want to know is am I going in the right direction.
Would that VBA code work as intended, ie if I put it in the rightmost query column, or rather call it, would it run its count on the records already sorted and filter by the previous criteria.
And then, from a logical point of view is the following correct in the VBA (not the coding but my methodology)(I know I have to declare variables and set up the function inside a module).
---------------------------------
do
do
if
type of feeding = "bottle"
then
exclusive = "no"
while Medreccurrentnum = Medrecprevnum
if exclusive <> "no"
then exclbf = exclbf +1
exclbf = "yes"
until (condition which means there are no more records to look at)
-----------------
Note I am not sure about the condition for the until part, but I am sure I can figure that out, with some research.
Am I overthinking this problem? Is there some simpler way in access to do this in a query?
I enjoy the challenge of this work (I am switching my degree from biomed/electronics to Healthcare informatics as a result of this job) because it is pushing me into new territories. I know I ultimately have to learn SQL and at least get to an intermediate level with VBA
