Microsoft Access Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft Access Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 30th, 2004, 01:09 PM
USCitizen USCitizen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 19 USCitizen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 21 m 37 sec
Reputation Power: 0
multiselect listbox added to existing form

let's say i have a pre-existing form (called 'Demographics') which is using a table (called Demographics) as its record source. let's also say that its PK is called PatientID. let's say that i want to add a listbox to 'Demographics' which might be called 'Medications'. its purpose will be to record medications that each person reports (s)he's taking and as would be expected there can be more than one.

i think what i need to do is to create a way to permanently store this add'l information in the database so that it can be used with the existing information being collected by Demographics to generate reports, i.e. a report showing perhaps PatientID, Age, Gender, yadee yadee and all Medications being taken per each patient.

any user of the database should be able to go to any record using this form and add/delete/modify/view the information on it including the medications coded.

while i have got some ms a2k vba experience, this is why i'm writing.

hope this is making sense to someone but'd be glad to put more details on it as needed.

tia.

Reply With Quote
  #2  
Old December 30th, 2004, 02:06 PM
MrBullwinkle MrBullwinkle is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Wild and Wonderful, West Virginia
Posts: 27 MrBullwinkle User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to MrBullwinkle Send a message via AIM to MrBullwinkle Send a message via MSN to MrBullwinkle Send a message via Yahoo to MrBullwinkle
If you are asking how to store the data for patients then:

In the demographics table, you would have PatientID, Age, Gender, (Anything that has only 1 per patient...address, phone number)
For medications, since you can have more then 1 per patient, you need a second table that is linked by the PatientID.

In a table called Medications you have a field(column) called PatientID, Medication, and an autonumber field to use as a primary key

The two tables are linked by a 1-to-many relationship using the PatientIDs of both tables.

Reply With Quote
  #3  
Old December 30th, 2004, 03:17 PM
USCitizen USCitizen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 19 USCitizen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 21 m 37 sec
Reputation Power: 0
well....

i know about setting tables up with one-to-many relationships.

i wish it seemed as simple to me as this configuration must seem to be to you. the thing that i sense is that perhaps you've misunderstood something in my problem description....

your solution would have occurred to me immediately had i been talking about two independent forms each with the same linking variable (PatientID);

let's pretend that i were starting from scratch. no data entered as yet, ok?

i have a form that records Demographic information. on that table is a listbox with multiselect capability activated to allow for the selection of more than one Medication. here's my cunundrum,
w/o the listbox and its multiselect actuated, it would seem to me that all you would need is one underlying table, Demographics, yes? now you've gone and tossed this listbox into the mix: where does its information get stored and how does it relate to the Demographics data per patient. i've seen some uses of listboxes w/ multiselect actuated where the listbox is unbound, but i doubt that that would do here since the selections would be relevant only to that single patient and could not be counted upon to remain the same when scrolling through the Demographics form record by record.
am i posing the problem more clearly now?

tia.

Quote:
Originally Posted by MrBullwinkle
If you are asking how to store the data for patients then:

In the demographics table, you would have PatientID, Age, Gender, (Anything that has only 1 per patient...address, phone number)
For medications, since you can have more then 1 per patient, you need a second table that is linked by the PatientID.

In a table called Medications you have a field(column) called PatientID, Medication, and an autonumber field to use as a primary key

The two tables are linked by a 1-to-many relationship using the PatientIDs of both tables.

Reply With Quote
  #4  
Old December 30th, 2004, 04:13 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
A list box that is set to multiselect can not be bound to the forms underlying recordset. You will either need to make a table listing the medications available and use that as the rowsource or use a value list. But as MrBullwinkle suggested, have a table called medications that is linked to your patient ID. Then with code you can use the unbound multiselect list box to add the items selected to that table. You can show what medications have been given to a patient by using another listbox with the record source to that table and filtered by the patient ID. There isn't anyway to make one list box to function for both. A multiselect list box either in Simple or Extended has no value and is a read only.

lwells

Reply With Quote
  #5  
Old December 30th, 2004, 05:59 PM
USCitizen USCitizen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 19 USCitizen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 21 m 37 sec
Reputation Power: 0
although i certainly appreciate the depth and thought which this writer has welded into this reply, at this point i am feeling a little daunted by it...

would yet another approach be to draft a vba program which created a table with the selected medications, this table having a PatientID field as well, which would be filled with the PatientID from the Demographics form's underlying table?

tia.
Quote:
Originally Posted by lwells
A list box that is set to multiselect can not be bound to the forms underlying recordset. You will either need to make a table listing the medications available and use that as the rowsource or use a value list. But as MrBullwinkle suggested, have a table called medications that is linked to your patient ID. Then with code you can use the unbound multiselect list box to add the items selected to that table. You can show what medications have been given to a patient by using another listbox with the record source to that table and filtered by the patient ID. There isn't anyway to make one list box to function for both. A multiselect list box either in Simple or Extended has no value and is a read only.


lwells

Reply With Quote
  #6  
Old December 30th, 2004, 06:36 PM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
You could, but the question is why? If you use vba to create a table, then the code can only be used once..or you would have to delete the table when you are finished running the code to reuse the same code again. Creating and deleting tables would cause tremendous database bloat and possible corruption.

There appears to be a reluctance to just create a simple table to hold what the medications are for each patient which I am not following here. A simple table, a short piece of code to add records from a multiselect list box...is pretty straight forward database design and application. Is there something else about this application that is preventing you from doing this?

Just curious,
lwells

Reply With Quote
  #7  
Old December 30th, 2004, 08:34 PM
USCitizen USCitizen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 19 USCitizen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 21 m 37 sec
Reputation Power: 0
i have to get the sense i'm not following the method requirements you're suggesting. first of all i well understand that this could be done probably w/ less angst (on my part anyway) w/ a subtable/form that recorded each patient's meds and was correlated via a common PatientID. that having been said, i was reading somebody's ms a2k development book and came 'cross a reference to multiselect listboxes which got me on this thread. these are one control i have used only once in the several applications i developed since getting into a2k. so much for history. now, if you want to go forward and illustrate your proposal with some concrete coding, i'm prepared to try to think it through and understand it.

tia.


Quote:
Originally Posted by lwells
You could, but the question is why? If you use vba to create a table, then the code can only be used once..or you would have to delete the table when you are finished running the code to reuse the same code again. Creating and deleting tables would cause tremendous database bloat and possible corruption.

There appears to be a reluctance to just create a simple table to hold what the medications are for each patient which I am not following here. A simple table, a short piece of code to add records from a multiselect list box...is pretty straight forward database design and application. Is there something else about this application that is preventing you from doing this?

Just curious,
lwells

Reply With Quote
  #8  
Old December 31st, 2004, 08:39 AM
lwells lwells is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Sep 2004
Posts: 632 lwells User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 21 h 59 m 38 sec
Reputation Power: 5
tia,

Okay, here is what you do.

1) Create a table and name it tblMedicationsGiven. Give the table three fields. The first field will be the Primary Key and Autonumber. The second field will be PatientID and will be a number. The third field will be Medications and will be a text.

2) In table relationships window join the PatientID from your demographics table to this table with the PatientID. This will give you the one-to-many relationship between patient and medications given.

3) On your Demographics form, place two unbound listboxes. Name the first unbound list box lstMedicationsGiven, and the second list box name it lstMedications.

For the rowsource of the lstMedications - this is where you will select the available medications from. So you can either choose to create a seperate table listing all the available medications or use the value list type and make the list yourself as the rowsource.

4) On the forms On Current Event place the following code:

Dim intID As Integer
Dim strSQL As String
intID = PatientID

strSQL = "SELECT tblMedicationsGiven.* " & _
"FROM tblMedicationsGiven " & _
"WHERE tblMedicationsGiven.PatientID =" & intID & ";"
lstMedicationsGiven.RowSource = strSQL
Me.Refresh

This will keep the list box named lstMedicationsGiven in sync with each patient record.
So as you scroll through each patients records the list box will display what medications were given to that patient only.

5) On the After Update event of the listbox named lstMedications place this code:

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim varItem As Variant
Dim strSQL As String
Dim intID As Integer
intID = PatientID
Set db = CurrentDb()
strSQL = "SELECT tblMedicationsGiven.* FROM tblMedicationsGiven;"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
For Each varItem In Me!lstMedications.ItemsSelected
If rs.RecordCount > 0 Then
rs.MoveLast
End If
With rs
.AddNew
rs!PatientID.Value = intID
rs!Medications.Value = Me!lstMedications.ItemData(varItem)
.Update
End With
Next varItem
Set db = Nothing
Set rs = Nothing
lstMedicationsGiven.Requery

Make sure this list box (lstMedications) is set to either multiselect Simple or Extended.

Now as the user selects medications from this list, it will add those medications to the records for that patient and automatically refresh the listbox lstMedicationsGiven so the user can see what was given to the patient.

I believe this is what you were wanting to do.

lwells

Last edited by lwells : December 31st, 2004 at 08:52 AM.

Reply With Quote
  #9  
Old December 31st, 2004, 01:28 PM
USCitizen USCitizen is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 19 USCitizen User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 21 m 37 sec
Reputation Power: 0
would that i could but trial this mighty code today but alas the holiday gods have conspired against this lofty intention....

will definitely give it a spin 'next year' (ie. monday) and get back w/ more feedback.

USCitizen.

ps: tia = thanks in advance
pps: closing this with every best wish for a happy new year!

Quote:
Originally Posted by lwells
tia,

Okay, here is what you do.

1) Create a table and name it tblMedicationsGiven. Give the table three fields. The first field will be the Primary Key and Autonumber. The second field will be PatientID and will be a number. The third field will be Medications and will be a text.

2) In table relationships window join the PatientID from your demographics table to this table with the PatientID. This will give you the one-to-many relationship between patient and medications given.

3) On your Demographics form, place two unbound listboxes. Name the first unbound list box lstMedicationsGiven, and the second list box name it lstMedications.

For the rowsource of the lstMedications - this is where you will select the available medications from. So you can either choose to create a seperate table listing all the available medications or use the value list type and make the list yourself as the rowsource.

4) On the forms On Current Event place the following code:

Dim intID As Integer
Dim strSQL As String
intID = PatientID

strSQL = "SELECT tblMedicationsGiven.* " & _
"FROM tblMedicationsGiven " & _
"WHERE tblMedicationsGiven.PatientID =" & intID & ";"
lstMedicationsGiven.RowSource = strSQL
Me.Refresh

This will keep the list box named lstMedicationsGiven in sync with each patient record.
So as you scroll through each patients records the list box will display what medications were given to that patient only.

5) On the After Update event of the listbox named lstMedications place this code:

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim varItem As Variant
Dim strSQL As String
Dim intID As Integer
intID = PatientID
Set db = CurrentDb()
strSQL = "SELECT tblMedicationsGiven.* FROM tblMedicationsGiven;"
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
For Each varItem In Me!lstMedications.ItemsSelected
If rs.RecordCount > 0 Then
rs.MoveLast
End If
With rs
.AddNew
rs!PatientID.Value = intID
rs!Medications.Value = Me!lstMedications.ItemData(varItem)
.Update
End With
Next varItem
Set db = Nothing
Set rs = Nothing
lstMedicationsGiven.Requery

Make sure this list box (lstMedications) is set to either multiselect Simple or Extended.

Now as the user selects medications from this list, it will add those medications to the records for that patient and automatically refresh the listbox lstMedicationsGiven so the user can see what was given to the patient.

I believe this is what you were wanting to do.

lwells

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft Access Development > multiselect listbox added to existing form


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT