Next on my wish list...

D

Dave

Each of my patients may have anywhere from 1 - 50 different
antibodies. The table setup is not a problem. But I would like a form
with a list box (or something else) that lists all the possible
antibodies ( up to 50 of them) to choose from. I would like a check
box beside each antibody choice so that the user would check one or
more antibody choices which would then go into the patient's record.

Each test date, BTW the choices would be made again as they may not be
the same.

What control should I use for this and is there code that should be
attached to the check box?

Thanks in advance

Dave
 
B

BruceM

When you say there is no problem with the table setup, do you mean there is
a Patient table, and Antibody table, and a PatientAntibody junction table?

If so, do you intend to select from a listing of all antibodies the ones
that will be entered into the PatientAntibody table, then have several of
the related records created at the same time?
 
D

Dave

When you say there is no problem with the table setup, do you mean there is
a Patient table, and Antibody table, and a PatientAntibody junction table?

If so, do you intend to select from a listing of all antibodies the ones
that will be entered into the PatientAntibody table, then have several of
the related records created at the same time?










- Show quoted text -

Yes, That's exactly what I mean.

Dave
 
D

Dad

Dave said:
Each of my patients may have anywhere from 1 - 50 different
antibodies. The table setup is not a problem. But I would like a form
with a list box (or something else) that lists all the possible
antibodies ( up to 50 of them) to choose from. I would like a check
box beside each antibody choice so that the user would check one or
more antibody choices which would then go into the patient's record.

Each test date, BTW the choices would be made again as they may not be
the same.

What control should I use for this and is there code that should be
attached to the check box?

Thanks in advance

Dave
 
B

BruceM

OK, it's hard to tell without knowing a few details. When you said you want
to insert the antibodies into the patient's record it sounded as if you
meant to insert the list into the main record. Perhaps you meant you are
using a multi-value field from Access 2007.

If it was me I would probably create a subform and select the anitbodies one
at a time. No doubt what you want can be done, but it could be rather
involved.

This is something I saved a while ago from a posting Allen Browne made in a
newsgroup:

********
To add new records with a loop:

Function MakeData(HowMany As Long)
Dim lngI As Long
Dim rs As DAO.Recordset

Set rs = DBEngine(0)(0).OpenRecordset("MyTable")
With rs
For lngI = 1 To HowMany
.AddNew
!SomeField = SomeValue
!AnotherField = AnotherValue
'etc.
.Update
Next
End With
rs.Close
Set rs = Nothing
End Function

It may be easier to execute one Append query statement, and use a Cartesian
product to generate the desired number of records. That's just a matter of
having a table that counts from 1 to the maximum number of records you would
ever need to add. Include this table in your append query, with no join
between tables. Use criteria under the counter field to get the desired
number of records.

*********

To get the SomeValue items you culd use something like this. lstTest is the
name of the multi-select list box. This could be a command button code:

Dim varItem As Variant 'Selected items
Dim colAB As New Collection 'Collection of selected items
Dim i As Integer

'Loop through the items Selected in the list box.
With Me.lstTest
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
colAB.Add .ItemData(varItem)
End If
Next
End With

For i = 1 To colAB.Count
Debug.Print colAB(i)
Next i

This shows the code with Debug.Print, but I expect you could do something
like this to combine the two:

Function MakeData()

Dim lngI As Long, lngParent as Long, lngCount as long
Dim rs As DAO.Recordset
Dim varItem As Variant 'Selected items
Dim colAB As New Collection 'Collection of selected items

lngParent = Me.PrimaryKeyField

'Loop through the items Selected in the list box.
With Me.lstTest
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
colAB.Add .ItemData(varItem)
End If
Next
End With

lngCount = colAB.Count

Set rs = DBEngine(0)(0).OpenRecordset("JunctionTable")
With rs
For lngI = 1 To lngCount
.AddNew
!FK_Field = lngParent
!AntibodyID = colAB( LngI - 1)
.Update
Next
End With
rs.Close
Set rs = Nothing
End Function

I believe LngI -1 is necessary because the collection items numbering is
zero-based.

I learned about looping through list box items from Allen Browne, and about
using a collection from Albert Kallal. I have not seen them put together in
quite this way. I'm afraid I don't have the time to fully test the code
now, but I think it will work, or at least point you in the right direction.
Of course, you will need to tweak it for the names of your tables, fields,
etc.

Note that the code could be directly in a command button click event, or the
function could be called from the click event.


When you say there is no problem with the table setup, do you mean there
is
a Patient table, and Antibody table, and a PatientAntibody junction table?

If so, do you intend to select from a listing of all antibodies the ones
that will be entered into the PatientAntibody table, then have several of
the related records created at the same time?










- Show quoted text -

Yes, That's exactly what I mean.

Dave
 
B

BruceM

I did some testing, and the code seems to work with one modification:
LngI - 1 does not work. I must have gotten the wrong idea about the
numbering being zero-based. Remove the -1 (just use LngI) and it works.
Allen Browne has code to select or deselect all items in a multi-select list
box:
http://allenbrowne.com/func-12.html

I placed the code directly into the Click event of a command button. The
last line of code calls the ClearList function. The MakeData code could
also be in a function. In the click event, call MakeData, then ClearList.
 

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