Multiple Tables; Identical Format Slightly Different Data

R

ryguy7272

I’m helping a friend with a small DB and it’s coming along well, except for
one part. I am actually fairly close to finishing this thing, but I’m stuck
on something. The DB is for storing and analyzing information for hospital
patients.

Basically a doctor will review a patient and make an update, using a Form,
to a Table with various metrics. The doctor may do between 1 review and 8
reviews for each patient, depending on how the patient responds to
prescription medication. It is easy enough to capture the information for
the initial review, but I am unsure of how to capture information for
subsequent reviews. The for review number 2, the doctor would want to see
the results from review number 1, and make appropriate changes, but not
overwrite what is saved for review number 1. So on an so forth. For review
number 8, the doctor would want to see the data from the prior seven reviews,
but not overwrite that data. Does anyone have an idea of how to set this up?
I’m guessing it will require 8 tables, and all must be linked via the
patient ID number. Maybe some kind of structure like a SubForm, embedded in
the main Form.

I am trying to figure out how to proceed... I’d sincerely appreciate any
recommendations, suggestions, guidance, etc., with this. Basically, I am
thinking of setting up multiple tables, with identical formats, and but with
slightly different data.


Regards,
Ryan---
 
P

pietlinden

I’m helping a friend with a small DB and it’s coming along well, except for
one part.  I am actually fairly close to finishing this thing, but I’m stuck
on something.  The DB is for storing and analyzing information for hospital
patients.  

Basically a doctor will review a patient and make an update, using a Form,
to a Table with various metrics.  The doctor may do between 1 review and 8
reviews for each patient, depending on how the patient responds to
prescription medication.  It is easy enough to capture the information for
the initial review, but I am unsure of how to capture information for
subsequent reviews.  The for review number 2, the doctor would want to see
the results from review number 1, and make appropriate changes, but not
overwrite what is saved for review number 1.  So on an so forth.  Forreview
number 8, the doctor would want to see the data from the prior seven reviews,
but not overwrite that data.  Does anyone have an idea of how to set this up?
 I’m guessing it will require 8 tables, and all must be linked via the
patient ID number.  Maybe some kind of structure like a SubForm, embedded in
the main Form.

I am trying to figure out how to proceed...  I’d sincerely appreciateany
recommendations, suggestions, guidance, etc., with this.  Basically, I am
thinking of setting up multiple tables, with identical formats, and but with
slightly different data.

Regards,
Ryan---

First off, just open multiple instances of the form:
http://allenbrowne.com/ser-35.html

Then make all of the form's data read only. (So the doctor can't
accidentally change an old record). Put a button on the form that
enables him to copy the data to a new record and then open another
copy of the form that has the AllowEdits property set to True. Then
the user can modify this record and save it, and you have one form to
deal with instead of 8 or whatever... just disable/enable some of the
controls when you open the editable one....
 
R

ryguy7272

Thanks for sharing this; I've never seen it before. The concept is kind of
like a SubForm, right. What kind of functionality does this process offer
over and above what I can get with a SubForm?

Regrads,
Ryan--
 
R

ryguy7272

Oh no! I think I've really hit a wall this time. I'm back to my original
design, with 8 tables. I can easily filter for nulls in a Query, and display
all relevant records in a SubForm, but I can't, for the life of me, figure
out how I'm going to get a Form to know which table to add new records to!!
If the doctor has seen the patient 1 time, I can easily display the
patient-reviews in a SubForm, but how can I control the main Form so that it
adds the results of the 2nd review to the 2nd Table? Below is the code that
sends the results of the patient-review to the 1st Table:

Private Sub Command19_Click()

Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim rstPatientTable As ADODB.Recordset
Dim strCnn As String
'Dim mydb As DAO.Database
Dim mydb As String


'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "C:\RTDA Tool.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn

' Open contact table.
Set rstPatientTable = New ADODB.Recordset
rstPatientTable.CursorType = adOpenKeyset
rstPatientTable.LockType = adLockOptimistic
'rstPatientTable.Open "PatientTable", cnn1, , , adCmdTable
rstPatientTable.Open "SELECT * FROM PatientTable WHERE
(((PatientTable.MR)=" & Me!MR & "));", cnn1

'get the new record data
rstPatientTable.Update

rstPatientTable!Skin = Skin
rstPatientTable!Mucous_Membrane = Mucous_Membrane
rstPatientTable!Eye = Eye
rstPatientTable!Ear = Ear
rstPatientTable!Salivery_Gland = Salivery_Gland
rstPatientTable!Pharynx_and_Esophogus = Pharynx_and_Esophogus
rstPatientTable!Larynx = Larynx
rstPatientTable!Upper_GI = Upper_GI
rstPatientTable!Lower_GI_Including_Pelvis = Lower_GI_Including_Pelvis
rstPatientTable!Lung = Lung
rstPatientTable!Genitourinary = Genitourinary
rstPatientTable!Heart = Heart
rstPatientTable!CNS = CNS
rstPatientTable!WBC = WBC
rstPatientTable!Platelets = Platelets
rstPatientTable!Neutrophis = Neutrophis
rstPatientTable!Hemoglobin = Hemoglobin
rstPatientTable!Hematocrit = Hematocrit
rstPatientTable!Current_Weight = Current_Weight
rstPatientTable!Assessment_Date = Assessment_Date
rstPatientTable!StatusCheck_Comments = StatusCheck_Comments


rstPatientTable.Update

' Show the newly added data.
MsgBox "Patient: " & Me!SearchStatusCheckSubForm.Form.[FirstName] &
" " & Me!SearchStatusCheckSubForm.Form.[LastName] & " has been successfully
updated!!"


'close connections
rstPatientTable.Close
cnn1.Close


Else
MsgBox "An Error has occurred, please check and try again"
End If

End Sub

I'd appreciate any thoughts or insights on this.

Thanks,
Ryan---
 
B

Bob Quintal

Oh no! I think I've really hit a wall this time. I'm back to my
original design, with 8 tables. I can easily filter for nulls in
a Query, and display all relevant records in a SubForm, but I
can't, for the life of me, figure out how I'm going to get a Form
to know which table to add new records to!! If the doctor has
seen the patient 1 time, I can easily display the patient-reviews
in a SubForm, but how can I control the main Form so that it adds
the results of the 2nd review to the 2nd Table? Below is the code
that sends the results of the patient-review to the 1st Table:

No! No! No!!!!!!!!

Only use 1 table! 1 Table! 1 Table!

You add a new column for the ReviewID, and set the value of this
column to
nz(max("ReviewId","ReviewTable","PatientID= " & me.patientID"
in code, when you add the Review record.

And you should split that table to hold the patient's common info
(name, address, dob, etc.),, with a separate table for the review
criteria, plus the patient ID which is the key into the first table.


Private Sub Command19_Click()

Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim rstPatientTable As ADODB.Recordset
Dim strCnn As String
'Dim mydb As DAO.Database
Dim mydb As String


'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "C:\RTDA Tool.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn

' Open contact table.
Set rstPatientTable = New ADODB.Recordset
rstPatientTable.CursorType = adOpenKeyset
rstPatientTable.LockType = adLockOptimistic
'rstPatientTable.Open "PatientTable", cnn1, , , adCmdTable
rstPatientTable.Open "SELECT * FROM PatientTable WHERE
(((PatientTable.MR)=" & Me!MR & "));", cnn1

'get the new record data
rstPatientTable.Update

rstPatientTable!Skin = Skin
rstPatientTable!Mucous_Membrane = Mucous_Membrane
rstPatientTable!Eye = Eye
rstPatientTable!Ear = Ear
rstPatientTable!Salivery_Gland = Salivery_Gland
rstPatientTable!Pharynx_and_Esophogus =
Pharynx_and_Esophogus rstPatientTable!Larynx = Larynx
rstPatientTable!Upper_GI = Upper_GI
rstPatientTable!Lower_GI_Including_Pelvis =
Lower_GI_Including_Pelvis rstPatientTable!Lung = Lung
rstPatientTable!Genitourinary = Genitourinary
rstPatientTable!Heart = Heart
rstPatientTable!CNS = CNS
rstPatientTable!WBC = WBC
rstPatientTable!Platelets = Platelets
rstPatientTable!Neutrophis = Neutrophis
rstPatientTable!Hemoglobin = Hemoglobin
rstPatientTable!Hematocrit = Hematocrit
rstPatientTable!Current_Weight = Current_Weight
rstPatientTable!Assessment_Date = Assessment_Date
rstPatientTable!StatusCheck_Comments =
StatusCheck_Comments


rstPatientTable.Update

' Show the newly added data.
MsgBox "Patient: " &
Me!SearchStatusCheckSubForm.Form.[FirstName] &
" " & Me!SearchStatusCheckSubForm.Form.[LastName] & " has been
successfully updated!!"


'close connections
rstPatientTable.Close
cnn1.Close


Else
MsgBox "An Error has occurred, please check and try again"
End If

End Sub

I'd appreciate any thoughts or insights on this.

Thanks,
Ryan---
 
R

ryguy7272

Alllll Rightyyy Then!! This is starting to make sense now. Bob, how do i
implement what you proposed? The line add a column and set the value to
'nz(max("ReviewId","ReviewTable","PatientID= " & me.patientID"
in code, when you add the Review record' sounds like it will work. Can you
walk me through the process; step by step? Conceptually, it makes sense, in
reality, I don't believe I know how to do this. I now have one Table named
tblStatusCheck, whcihc has all the data points for the review for patients.
This is linked to my 'Patienttable' which has all relevant information for
patients. The join line is 'include ALL records from the PatientTable and
only those records from the tblStatusCheck where the joined fields are
equal'. Please walk me through the next step or two. I believe this is the
last major obstacle that I need to deal with; I'd like to get a handle on
this soon.

Thanks so much!
Ryan--



--
RyGuy


Bob Quintal said:
Oh no! I think I've really hit a wall this time. I'm back to my
original design, with 8 tables. I can easily filter for nulls in
a Query, and display all relevant records in a SubForm, but I
can't, for the life of me, figure out how I'm going to get a Form
to know which table to add new records to!! If the doctor has
seen the patient 1 time, I can easily display the patient-reviews
in a SubForm, but how can I control the main Form so that it adds
the results of the 2nd review to the 2nd Table? Below is the code
that sends the results of the patient-review to the 1st Table:

No! No! No!!!!!!!!

Only use 1 table! 1 Table! 1 Table!

You add a new column for the ReviewID, and set the value of this
column to
nz(max("ReviewId","ReviewTable","PatientID= " & me.patientID"
in code, when you add the Review record.

And you should split that table to hold the patient's common info
(name, address, dob, etc.),, with a separate table for the review
criteria, plus the patient ID which is the key into the first table.


Private Sub Command19_Click()

Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim rstPatientTable As ADODB.Recordset
Dim strCnn As String
'Dim mydb As DAO.Database
Dim mydb As String


'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "C:\RTDA Tool.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn

' Open contact table.
Set rstPatientTable = New ADODB.Recordset
rstPatientTable.CursorType = adOpenKeyset
rstPatientTable.LockType = adLockOptimistic
'rstPatientTable.Open "PatientTable", cnn1, , , adCmdTable
rstPatientTable.Open "SELECT * FROM PatientTable WHERE
(((PatientTable.MR)=" & Me!MR & "));", cnn1

'get the new record data
rstPatientTable.Update

rstPatientTable!Skin = Skin
rstPatientTable!Mucous_Membrane = Mucous_Membrane
rstPatientTable!Eye = Eye
rstPatientTable!Ear = Ear
rstPatientTable!Salivery_Gland = Salivery_Gland
rstPatientTable!Pharynx_and_Esophogus =
Pharynx_and_Esophogus rstPatientTable!Larynx = Larynx
rstPatientTable!Upper_GI = Upper_GI
rstPatientTable!Lower_GI_Including_Pelvis =
Lower_GI_Including_Pelvis rstPatientTable!Lung = Lung
rstPatientTable!Genitourinary = Genitourinary
rstPatientTable!Heart = Heart
rstPatientTable!CNS = CNS
rstPatientTable!WBC = WBC
rstPatientTable!Platelets = Platelets
rstPatientTable!Neutrophis = Neutrophis
rstPatientTable!Hemoglobin = Hemoglobin
rstPatientTable!Hematocrit = Hematocrit
rstPatientTable!Current_Weight = Current_Weight
rstPatientTable!Assessment_Date = Assessment_Date
rstPatientTable!StatusCheck_Comments =
StatusCheck_Comments


rstPatientTable.Update

' Show the newly added data.
MsgBox "Patient: " &
Me!SearchStatusCheckSubForm.Form.[FirstName] &
" " & Me!SearchStatusCheckSubForm.Form.[LastName] & " has been
successfully updated!!"


'close connections
rstPatientTable.Close
cnn1.Close


Else
MsgBox "An Error has occurred, please check and try again"
End If

End Sub

I'd appreciate any thoughts or insights on this.

Thanks,
Ryan---
 
B

Bob Quintal

Alllll Rightyyy Then!! This is starting to make sense now. Bob,
how do i implement what you proposed? The line add a column and
set the value to 'nz(max("ReviewId","ReviewTable","PatientID= " &
me.patientID" in code, when you add the Review record' sounds like
it will work. Can you walk me through the process; step by step?
Conceptually, it makes sense, in reality, I don't believe I know
how to do this. I now have one Table named tblStatusCheck, whcihc
has all the data points for the review for patients. This is
linked to my 'Patienttable' which has all relevant information for
patients. The join line is 'include ALL records from the
PatientTable and only those records from the tblStatusCheck where
the joined fields are equal'. Please walk me through the next
step or two. I believe this is the last major obstacle that I
need to deal with; I'd like to get a handle on this soon.

Thanks so much!
Ryan--

Ok, You need to add the StatusCheckID to the table tblStatusCheck.
It should be type integer or long integer. Make your primary key the
combination of the two fields "PatientID and StatusCheckID.
I'll get flack from some religious zealots because I do not
recommend an autonumber, but you need a unique index with those two
fields anyways if you use an autonumber, so an autonumber is
redundant.

I would set up a patients form, with the StatusCheck table as the
source for a subform. . In the mainform, set up a textbox, unbound,
that holds the expression
= nz(max("StatusCheckID","tblStatusCheck","PatientID = " & forms!
frmPatients!patioentID & )
That assumes the names for the fields and form, I'm using what I
would name them, yours may be named differently..I would label that
control "existing Status Reviews" and name it txtStatusCount.

I'd set the link child fields to PatientID, StatusCountID
The parent fields wqould be PatienntId, txtStatusCount.
The subform will therefore only show the highest numbered (most
recent) Status for the patient. If you want to show all the Status
Reviews drop the second field from both parent and child links.


On the subform, I'd have a button Labeled "New Status" that reads
the value from the parent form, adds 1 and stuffs that into the new
record.
To change your code below to create a new record instead of updating
the existing one, just change the line
rstPatientTable.Update to rstPatientTable.AddNew

Q

--
RyGuy


Bob Quintal said:
Oh no! I think I've really hit a wall this time. I'm back to
my original design, with 8 tables. I can easily filter for
nulls in a Query, and display all relevant records in a
SubForm, but I can't, for the life of me, figure out how I'm
going to get a Form to know which table to add new records to!!
If the doctor has seen the patient 1 time, I can easily
display the patient-reviews in a SubForm, but how can I control
the main Form so that it adds the results of the 2nd review to
the 2nd Table? Below is the code that sends the results of the
patient-review to the 1st Table:

No! No! No!!!!!!!!

Only use 1 table! 1 Table! 1 Table!

You add a new column for the ReviewID, and set the value of this
column to
nz(max("ReviewId","ReviewTable","PatientID= " & me.patientID"
in code, when you add the Review record.

And you should split that table to hold the patient's common info
(name, address, dob, etc.),, with a separate table for the review
criteria, plus the patient ID which is the key into the first
table.


Private Sub Command19_Click()

Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim rstPatientTable As ADODB.Recordset
Dim strCnn As String
'Dim mydb As DAO.Database
Dim mydb As String


'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "C:\RTDA Tool.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn

' Open contact table.
Set rstPatientTable = New ADODB.Recordset
rstPatientTable.CursorType = adOpenKeyset
rstPatientTable.LockType = adLockOptimistic
'rstPatientTable.Open "PatientTable", cnn1, , , adCmdTable
rstPatientTable.Open "SELECT * FROM PatientTable WHERE
(((PatientTable.MR)=" & Me!MR & "));", cnn1

'get the new record data
rstPatientTable.Update

rstPatientTable!Skin = Skin
rstPatientTable!Mucous_Membrane = Mucous_Membrane
rstPatientTable!Eye = Eye
rstPatientTable!Ear = Ear
rstPatientTable!Salivery_Gland = Salivery_Gland
rstPatientTable!Pharynx_and_Esophogus =
Pharynx_and_Esophogus rstPatientTable!Larynx = Larynx
rstPatientTable!Upper_GI = Upper_GI
rstPatientTable!Lower_GI_Including_Pelvis =
Lower_GI_Including_Pelvis rstPatientTable!Lung = Lung
rstPatientTable!Genitourinary = Genitourinary
rstPatientTable!Heart = Heart
rstPatientTable!CNS = CNS
rstPatientTable!WBC = WBC
rstPatientTable!Platelets = Platelets
rstPatientTable!Neutrophis = Neutrophis
rstPatientTable!Hemoglobin = Hemoglobin
rstPatientTable!Hematocrit = Hematocrit
rstPatientTable!Current_Weight = Current_Weight
rstPatientTable!Assessment_Date = Assessment_Date
rstPatientTable!StatusCheck_Comments =
StatusCheck_Comments


rstPatientTable.Update

' Show the newly added data.
MsgBox "Patient: " &
Me!SearchStatusCheckSubForm.Form.[FirstName] &
" " & Me!SearchStatusCheckSubForm.Form.[LastName] & " has been
successfully updated!!"


'close connections
rstPatientTable.Close
cnn1.Close


Else
MsgBox "An Error has occurred, please check and try again"
End If

End Sub

I'd appreciate any thoughts or insights on this.

Thanks,
Ryan---
 
K

Ken Sheridan

Ryan:

I hate to be the ghost at the feast as its clear you've invested a lot of
time and effort in getting this far, but on the basis that 'the first thing
to do when in a hole is to stop digging' I do feel I should draw your
attention to the flaws in your model.

The problem here is that you've included separate columns in PatientTable
for each category of clinical assessment, Mucous_membrane, Eye, Ear etc.
This is what is known as 'encoding data as column headings'. Each column
represents a data value of an attribute, AssessmentCategory say, of an entity
type ClinicalAssessmentCategories say (you may well have better terms for
them, but that's bye-the-bye). A fundamental principle of the database
relational model (the 'information principle) is that data is stored as
explicit values at column positions at rows in tables.

The correct way to model this would be to have a
ClinicalAssessmentCategories table, with column AssessmentCategory. Each row
in this table would represent one category of clinical assessment.

A PatientReviews table recording each patient review would have foreign keys
PatientID and DoctorID, each referencing the primary key of tables Patients
and Doctors respectively, and a column ReviewDate. In combination these
would form the table's composite primary key. This table would also contain
a Comments column as this is specific to each patient review rather than the
individual clinical assessments within that review.

To record the individual clinical assessments per patient review would
require a PatientReviewDetails table. This would have composite foreign key
of PatientID, DoctorID and ReviewDate referencing the composite primary key
of PatientReviews. In addition it would have another foreign key column
AssessmentCategory referencing the primary key of
ClinicalAssessmentCategories and a column AssessmentResult say to record the
result of each assessment.

As regards the interface one approach would be to have form based on
PatientReviews with combo boxes bund to the PatientID and DoctorID columns
and text box controls bound to the ReviewDate and Comments columns. Within
this for would be a continuous form view subform based on
PatientReviewDetails and liked to the parent form by having
PatientID;DoctorID;ReviewDate as the subform control's LinkMasterFields and
LinkChildFields properties.

Once the patient, doctor and review date have been entered in the parent
form its then merely a question of inserting one row into the subform for
each category of clinical assessment undertaken in the review.

When a new review is undertaken it would be possible to automatically insert
rows into the PatientReviewDetails table with values to match the last review
for this patient if desired so that each can then be left as is, or changed
as appropriate. This could be done in code in the parent form's module like
so:

Const conMESSAGE = _
"A doctor, patient and review date must be entered."

Dim cmd As ADODB.Command
Dim strSQL As String

Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText

' first ensure all required values are present
If IsNull(Me.DoctorID) Or IsNull(Me.PatientID) _
Or IsNull(Me.ReviewDate) Then
MsgBox, conMESSAGE, "Invalid Operation"
Exit Sub
End If

'ensure current record is saved
Me.Dirty = False

' insert new rows into table with same values as latest
' review for current doctor/patient
strSQL = "INSERT INTO PatientReviewDetails" & _
"(ReviewDate,DoctorID, PatientID," & _
"AssessmentCategory,AssessmentResult) " & _
"SELECT #" & Format(Me.ReviewDate,"yyyy-mm-dd") & "#." & _
"DoctorID, PatientID,AssessmentCategory,AssessmentResult " & _
"FROM PatientReviewDetails " & _
"WHERE PatientID = " & Me.PatientID & _
" AND DoctorID = " & Me.DoctorID & _
" AND ReviewDate = " & _
"(SELECT MAX(ReviewDate) " & _
"FROM PatientReviewDetails " & _
"WHERE PatientID = " & Me.PatientID & _
" AND DoctorID = " & Me.DoctorID & ")"

cmd.CommandText = strSQL
cmd.Execute

' requery subform to show new rows
Me.sfcPatientReviewDetails.Requery


where sfcPatientReviewDetails is the name of the subform control in the
parent form's Controls collection.

As well as being theoretically sound the model described above does of
course have practical implications in that should the users wish to amend the
basis of clinical assessment, e.g. by adding a new category or renaming an
existing category this is merely a case of editing the
ClinicalAssessmentCategories table, for which provision cam be made in the
interface. By 'encoding the data as column headings' on the other hand would
require an amendment both of the table definition and of your code which
assigns values to the columns.

Ken Sheridan
Stafford, England

ryguy7272 said:
Alllll Rightyyy Then!! This is starting to make sense now. Bob, how do i
implement what you proposed? The line add a column and set the value to
'nz(max("ReviewId","ReviewTable","PatientID= " & me.patientID"
in code, when you add the Review record' sounds like it will work. Can you
walk me through the process; step by step? Conceptually, it makes sense, in
reality, I don't believe I know how to do this. I now have one Table named
tblStatusCheck, whcihc has all the data points for the review for patients.
This is linked to my 'Patienttable' which has all relevant information for
patients. The join line is 'include ALL records from the PatientTable and
only those records from the tblStatusCheck where the joined fields are
equal'. Please walk me through the next step or two. I believe this is the
last major obstacle that I need to deal with; I'd like to get a handle on
this soon.

Thanks so much!
Ryan--



--
RyGuy


Bob Quintal said:
Oh no! I think I've really hit a wall this time. I'm back to my
original design, with 8 tables. I can easily filter for nulls in
a Query, and display all relevant records in a SubForm, but I
can't, for the life of me, figure out how I'm going to get a Form
to know which table to add new records to!! If the doctor has
seen the patient 1 time, I can easily display the patient-reviews
in a SubForm, but how can I control the main Form so that it adds
the results of the 2nd review to the 2nd Table? Below is the code
that sends the results of the patient-review to the 1st Table:

No! No! No!!!!!!!!

Only use 1 table! 1 Table! 1 Table!

You add a new column for the ReviewID, and set the value of this
column to
nz(max("ReviewId","ReviewTable","PatientID= " & me.patientID"
in code, when you add the Review record.

And you should split that table to hold the patient's common info
(name, address, dob, etc.),, with a separate table for the review
criteria, plus the patient ID which is the key into the first table.


Private Sub Command19_Click()

Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim rstPatientTable As ADODB.Recordset
Dim strCnn As String
'Dim mydb As DAO.Database
Dim mydb As String


'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "C:\RTDA Tool.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn

' Open contact table.
Set rstPatientTable = New ADODB.Recordset
rstPatientTable.CursorType = adOpenKeyset
rstPatientTable.LockType = adLockOptimistic
'rstPatientTable.Open "PatientTable", cnn1, , , adCmdTable
rstPatientTable.Open "SELECT * FROM PatientTable WHERE
(((PatientTable.MR)=" & Me!MR & "));", cnn1

'get the new record data
rstPatientTable.Update

rstPatientTable!Skin = Skin
rstPatientTable!Mucous_Membrane = Mucous_Membrane
rstPatientTable!Eye = Eye
rstPatientTable!Ear = Ear
rstPatientTable!Salivery_Gland = Salivery_Gland
rstPatientTable!Pharynx_and_Esophogus =
Pharynx_and_Esophogus rstPatientTable!Larynx = Larynx
rstPatientTable!Upper_GI = Upper_GI
rstPatientTable!Lower_GI_Including_Pelvis =
Lower_GI_Including_Pelvis rstPatientTable!Lung = Lung
rstPatientTable!Genitourinary = Genitourinary
rstPatientTable!Heart = Heart
rstPatientTable!CNS = CNS
rstPatientTable!WBC = WBC
rstPatientTable!Platelets = Platelets
rstPatientTable!Neutrophis = Neutrophis
rstPatientTable!Hemoglobin = Hemoglobin
rstPatientTable!Hematocrit = Hematocrit
rstPatientTable!Current_Weight = Current_Weight
rstPatientTable!Assessment_Date = Assessment_Date
rstPatientTable!StatusCheck_Comments =
StatusCheck_Comments


rstPatientTable.Update

' Show the newly added data.
MsgBox "Patient: " &
Me!SearchStatusCheckSubForm.Form.[FirstName] &
" " & Me!SearchStatusCheckSubForm.Form.[LastName] & " has been
successfully updated!!"


'close connections
rstPatientTable.Close
cnn1.Close


Else
MsgBox "An Error has occurred, please check and try again"
End If

End Sub

I'd appreciate any thoughts or insights on this.

Thanks,
Ryan---
 
R

ryguy7272

Thanks for all the information everyone. I must have tunnel vision; I think
the solution is staring me in the face, but I still don't 'see' it. I've got
a table named 'tblStatusCheck' and it has the following fields: Number (which
is now AutoNumber), MR (which is the ID number for patients), and all other
fields are for the patient's status, such as Skin, Eye, Ear, etc. I created
a SubForm from this source, and it is named subformStatusCheck. This SubForm
is in a Form named 'frmStatusCheck'. In the main part of the Form I have
three fields, which come from my 'PatientTable': MR (ID number for patients),
First Name, and Last Name. I also have a button on the Form, with this code
behind it:
Private Sub Command27_Click()
Me.subformStatusCheck.Form.Requery
End Sub

That requery part works great! However, I still can't figure out how to
concatenate the Number (in the tblStatusCheck) and the MR (in the
PatientTable). I'm using this function:
=nz(max("Number","tblStatusCheck","MR = " & Forms!PatientTable!MR &),0)
This just gives me: #Name?

Even when I truncate to the most basic elements, such as:
=nz([Forms!frmStatusCheck!],0)
I still get: #Name?

I even tried this:
=Me!subformStatusCheck!Form!Number
I still get: #Name?

I don't understand that!! That is how to reference a SubForm from a Form:
http://www.mvps.org/access/forms/frm0031.htm

The first part isn't working, but I'll fiddle with it more and try to get it
going soon. Even if that part was working, I'm a bit lost on the next part:
Bob, you said, 'I'd set the link child fields to PatientID, StatusCountID
The parent fields would be PatienntId, txtStatusCount.' Since my MR is
PatientID, I think I'm fine there, but what is the StatusCountID? The last
part, whcih is the txtStatusCount is the thing from above, that still isn't
working, but hopefully it will be working soon.

Ken, I appreciate your time and effort; all that typing ain't easy (I answer
lots of posts over in the Excel DG area, so I know). Your response is a
notch or two above where I am now, so I'm going to have to hold off on that a
for a bit. I've been using Access day in and day out for a year now;
probably have 2500 hours under my belt, but some of this stuff is kind of new
to me. I do a lot with Queries and Reports, but not much with Forms, so I'm
still trying to get acquainted with some of this stuff.

I feel like I am kind of close Bob. Can you give me another push, with the
naming conventions for my Form and my SubForm?

Regards,
Ryan---


--
RyGuy


Ken Sheridan said:
Ryan:

I hate to be the ghost at the feast as its clear you've invested a lot of
time and effort in getting this far, but on the basis that 'the first thing
to do when in a hole is to stop digging' I do feel I should draw your
attention to the flaws in your model.

The problem here is that you've included separate columns in PatientTable
for each category of clinical assessment, Mucous_membrane, Eye, Ear etc.
This is what is known as 'encoding data as column headings'. Each column
represents a data value of an attribute, AssessmentCategory say, of an entity
type ClinicalAssessmentCategories say (you may well have better terms for
them, but that's bye-the-bye). A fundamental principle of the database
relational model (the 'information principle) is that data is stored as
explicit values at column positions at rows in tables.

The correct way to model this would be to have a
ClinicalAssessmentCategories table, with column AssessmentCategory. Each row
in this table would represent one category of clinical assessment.

A PatientReviews table recording each patient review would have foreign keys
PatientID and DoctorID, each referencing the primary key of tables Patients
and Doctors respectively, and a column ReviewDate. In combination these
would form the table's composite primary key. This table would also contain
a Comments column as this is specific to each patient review rather than the
individual clinical assessments within that review.

To record the individual clinical assessments per patient review would
require a PatientReviewDetails table. This would have composite foreign key
of PatientID, DoctorID and ReviewDate referencing the composite primary key
of PatientReviews. In addition it would have another foreign key column
AssessmentCategory referencing the primary key of
ClinicalAssessmentCategories and a column AssessmentResult say to record the
result of each assessment.

As regards the interface one approach would be to have form based on
PatientReviews with combo boxes bund to the PatientID and DoctorID columns
and text box controls bound to the ReviewDate and Comments columns. Within
this for would be a continuous form view subform based on
PatientReviewDetails and liked to the parent form by having
PatientID;DoctorID;ReviewDate as the subform control's LinkMasterFields and
LinkChildFields properties.

Once the patient, doctor and review date have been entered in the parent
form its then merely a question of inserting one row into the subform for
each category of clinical assessment undertaken in the review.

When a new review is undertaken it would be possible to automatically insert
rows into the PatientReviewDetails table with values to match the last review
for this patient if desired so that each can then be left as is, or changed
as appropriate. This could be done in code in the parent form's module like
so:

Const conMESSAGE = _
"A doctor, patient and review date must be entered."

Dim cmd As ADODB.Command
Dim strSQL As String

Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandType = adCmdText

' first ensure all required values are present
If IsNull(Me.DoctorID) Or IsNull(Me.PatientID) _
Or IsNull(Me.ReviewDate) Then
MsgBox, conMESSAGE, "Invalid Operation"
Exit Sub
End If

'ensure current record is saved
Me.Dirty = False

' insert new rows into table with same values as latest
' review for current doctor/patient
strSQL = "INSERT INTO PatientReviewDetails" & _
"(ReviewDate,DoctorID, PatientID," & _
"AssessmentCategory,AssessmentResult) " & _
"SELECT #" & Format(Me.ReviewDate,"yyyy-mm-dd") & "#." & _
"DoctorID, PatientID,AssessmentCategory,AssessmentResult " & _
"FROM PatientReviewDetails " & _
"WHERE PatientID = " & Me.PatientID & _
" AND DoctorID = " & Me.DoctorID & _
" AND ReviewDate = " & _
"(SELECT MAX(ReviewDate) " & _
"FROM PatientReviewDetails " & _
"WHERE PatientID = " & Me.PatientID & _
" AND DoctorID = " & Me.DoctorID & ")"

cmd.CommandText = strSQL
cmd.Execute

' requery subform to show new rows
Me.sfcPatientReviewDetails.Requery


where sfcPatientReviewDetails is the name of the subform control in the
parent form's Controls collection.

As well as being theoretically sound the model described above does of
course have practical implications in that should the users wish to amend the
basis of clinical assessment, e.g. by adding a new category or renaming an
existing category this is merely a case of editing the
ClinicalAssessmentCategories table, for which provision cam be made in the
interface. By 'encoding the data as column headings' on the other hand would
require an amendment both of the table definition and of your code which
assigns values to the columns.

Ken Sheridan
Stafford, England

ryguy7272 said:
Alllll Rightyyy Then!! This is starting to make sense now. Bob, how do i
implement what you proposed? The line add a column and set the value to
'nz(max("ReviewId","ReviewTable","PatientID= " & me.patientID"
in code, when you add the Review record' sounds like it will work. Can you
walk me through the process; step by step? Conceptually, it makes sense, in
reality, I don't believe I know how to do this. I now have one Table named
tblStatusCheck, whcihc has all the data points for the review for patients.
This is linked to my 'Patienttable' which has all relevant information for
patients. The join line is 'include ALL records from the PatientTable and
only those records from the tblStatusCheck where the joined fields are
equal'. Please walk me through the next step or two. I believe this is the
last major obstacle that I need to deal with; I'd like to get a handle on
this soon.

Thanks so much!
Ryan--



--
RyGuy


Bob Quintal said:
in
Oh no! I think I've really hit a wall this time. I'm back to my
original design, with 8 tables. I can easily filter for nulls in
a Query, and display all relevant records in a SubForm, but I
can't, for the life of me, figure out how I'm going to get a Form
to know which table to add new records to!! If the doctor has
seen the patient 1 time, I can easily display the patient-reviews
in a SubForm, but how can I control the main Form so that it adds
the results of the 2nd review to the 2nd Table? Below is the code
that sends the results of the patient-review to the 1st Table:


No! No! No!!!!!!!!

Only use 1 table! 1 Table! 1 Table!

You add a new column for the ReviewID, and set the value of this
column to
nz(max("ReviewId","ReviewTable","PatientID= " & me.patientID"
in code, when you add the Review record.

And you should split that table to hold the patient's common info
(name, address, dob, etc.),, with a separate table for the review
criteria, plus the patient ID which is the key into the first table.



Private Sub Command19_Click()

Dim err As Integer
Dim cnn1 As ADODB.Connection
Dim rstPatientTable As ADODB.Recordset
Dim strCnn As String
'Dim mydb As DAO.Database
Dim mydb As String


'if no errors insert data
If err < 1 Then
' Open a connection.
Set cnn1 = New ADODB.Connection
mydb = "C:\RTDA Tool.mdb"
strCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & mydb
cnn1.Open strCnn

' Open contact table.
Set rstPatientTable = New ADODB.Recordset
rstPatientTable.CursorType = adOpenKeyset
rstPatientTable.LockType = adLockOptimistic
'rstPatientTable.Open "PatientTable", cnn1, , , adCmdTable
rstPatientTable.Open "SELECT * FROM PatientTable WHERE
(((PatientTable.MR)=" & Me!MR & "));", cnn1

'get the new record data
rstPatientTable.Update

rstPatientTable!Skin = Skin
rstPatientTable!Mucous_Membrane = Mucous_Membrane
rstPatientTable!Eye = Eye
rstPatientTable!Ear = Ear
rstPatientTable!Salivery_Gland = Salivery_Gland
rstPatientTable!Pharynx_and_Esophogus =
Pharynx_and_Esophogus rstPatientTable!Larynx = Larynx
rstPatientTable!Upper_GI = Upper_GI
rstPatientTable!Lower_GI_Including_Pelvis =
Lower_GI_Including_Pelvis rstPatientTable!Lung = Lung
rstPatientTable!Genitourinary = Genitourinary
rstPatientTable!Heart = Heart
rstPatientTable!CNS = CNS
rstPatientTable!WBC = WBC
rstPatientTable!Platelets = Platelets
rstPatientTable!Neutrophis = Neutrophis
rstPatientTable!Hemoglobin = Hemoglobin
rstPatientTable!Hematocrit = Hematocrit
rstPatientTable!Current_Weight = Current_Weight
rstPatientTable!Assessment_Date = Assessment_Date
rstPatientTable!StatusCheck_Comments =
StatusCheck_Comments


rstPatientTable.Update

' Show the newly added data.
MsgBox "Patient: " &
Me!SearchStatusCheckSubForm.Form.[FirstName] &
" " & Me!SearchStatusCheckSubForm.Form.[LastName] & " has been
successfully updated!!"


'close connections
rstPatientTable.Close
cnn1.Close


Else
MsgBox "An Error has occurred, please check and try again"
End If

End Sub

I'd appreciate any thoughts or insights on this.

Thanks,
Ryan---
 
J

John W. Vinson

Number (which
is now AutoNumber), MR (which is the ID number for patients), and all other
fields are for the patient's status, such as Skin, Eye, Ear, etc.

THAT IS YOUR PROBLEM.

This table design
IS
WRONG.

That's what people have been trying to tell you.

You have a many to many relationship: each patient has many different organs
(with a status for each); multple patients have data for skin, eyes, etc.

A properly normalized design would have three tables:

Patients
MR <primary key, unique id for the patient>
LastName
FirstName
<other biographical data>

Organs (or Tissues, or Issues, or whatever term works)
Organ <e.g. "Skin", "Eyes"> <primary key>

PatientStatus
MR <link to Patients>
Organ <joint primary key with MR>
Status <whatever you're now putting in the Skin field>

Rather than having multiple status *fields* for each patient, you will have
multple status *records* for each patient.
 
B

Bob Quintal

Thanks for all the information everyone. I must have tunnel
vision; I think the solution is staring me in the face, but I
still don't 'see' it. I've got a table named 'tblStatusCheck' and
it has the following fields: Number (which is now AutoNumber), MR
(which is the ID number for patients), and all other fields are
for the patient's status, such as Skin, Eye, Ear, etc. I created
a SubForm from this source, and it is named subformStatusCheck.
This SubForm is in a Form named 'frmStatusCheck'. In the main
part of the Form I have three fields, which come from my
'PatientTable': MR (ID number for patients), First Name, and Last
Name. I also have a button on the Form, with this code behind it:
Private Sub Command27_Click()
Me.subformStatusCheck.Form.Requery
End Sub

That requery part works great! However, I still can't figure out
how to concatenate the Number (in the tblStatusCheck) and the MR
(in the PatientTable). I'm using this function:
=nz(max("Number","tblStatusCheck","MR = " & Forms!PatientTable!MR
&),0) This just gives me: #Name?

The function is dmax, not max.
The ampersand in &),0) should not be there.

Concatenate? Stop right there. You do not want to concatenate.
There is absolutely no reason to concatenate.

Even when I truncate to the most basic elements, such as:
=nz([Forms!frmStatusCheck!],0)
I still get: #Name?

I even tried this:
=Me!subformStatusCheck!Form!Number
I still get: #Name?

I don't understand that!! That is how to reference a SubForm from
a Form: http://www.mvps.org/access/forms/frm0031.htm

The first part isn't working, but I'll fiddle with it more and try
to get it going soon. Even if that part was working, I'm a bit
lost on the next part: Bob, you said, 'I'd set the link child
fields to PatientID, StatusCountID The parent fields would be
PatienntId, txtStatusCount.' Since my MR is PatientID, I think
I'm fine there, but what is the StatusCountID? The last part,
whcih is the txtStatusCount is the thing from above, that still
isn't working, but hopefully it will be working soon.

Ok, the link Child Fields are MR, number.
The link parent fields are MR,and the textbox into which you'll put
the calculation above when you get it working.

You should not even need the requery once everything is working, as
the link fields will automatically requery the subform when you
change the record on the main form.
 
B

Bob Quintal

John,
before the original poster, ryguy, even starts to worry about
linking to multiple records in the subform, he needs to get the
linking to a single record in the subform working.

Let's teach the guy to walk in Access before we teach him how to do
a marathon.

Bob Quintal
 
A

a a r o n . k e m p f

I believe that it is illegal to use Jet database to store _ANYTHING_
involving hospitals, doctors, medical records-etc

It's called HIPAA.
Jet doesn't support audit trails-- so it's impossible to meet the
needs of HIPAA and use an obsolete database
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top