The Trans_In_Out column can be used in much the same way as a Null
DateReturned value in my example. Its not quite clear what the value of the
column would indicate, but if we assume that True (Yes) means the item has
been lent out then you can indicate in the combo box's list if an item is
available or not by setting the RowSource property for the Print_ID combobox
to:
SELECT Print_ID, Title, Author,
IIF(EXISTS
(SELECT *
FROM LendTransactions
WHERE LendTransactions.Print_ID = [Print Table].Print_ID
AND NOT Trans_In_Out), "Unavailable", "Available")
FROM [Print Table]
ORDER BY Title, Author;
in which case the other properties of the combo box would be something like
this:
BoundColum: 1
ColumnCount: 4
ColumnWidths: 0cm;3cm;3cm;3cm
ListWidth: 9cm
Alternatively you could restrict the list to available items only by means
of a RowSource property such as:
SELECT Print_ID, Title, Author
FROM [Print Table]
WHERE NOT EXISTS
(SELECT *
FROM LendTransactions
WHERE LendTransactions.Print_ID = [Print Table].Print_ID
AND Trans_In_Out)
ORDER BY Title, Author;
If you do the latter you would have to requery the combo box in its
AfterUpdate event procedure so that the combo box's list no longer shows the
item when you select from it in another row of the subform. This creates a
problem, however. Because you are using hidden surrogate keys, Print_ID etc,
you would not be able to see the selected Title in any existing rows in the
subform. The values of the underlying Print_ID column would be unchanged;
you'd just see empty combo boxes. There is a solution to this, which is to
use a hybrid control of a text box overlaid on a combo box so that it appears
to the user as a single control. You'll find an example of this at the
following link. It uses the local administrative units of Parish, District
and County in my area, but the principle is similar:
http://community.netscape.com/n/pfx/forum.aspx?nav=libraryMessages&ts....
I suspect that your current skill level might not be quite up to
implementing this, however, so my recommendation would be that you use the
easier first option, showing 'available, or 'unavailable' in the list. You
should still requery the combo box in its AfterUpdate event procedure, but
this would only change the value from 'available' to 'unavailable', not blank
out the control.
You'd need to validate the user's selection still, this time in the combo
box's BeforeUpdate event procedure, the code now being:
Const MESSAGE = "This item is currently unavailable."
Dim strCriteria As String
Dim blnIsRemoved As Boolean
strCriteria = "Print_ID = " & Me.Print_ID & " And Not Trans_In_Out)"
blnIsRemoved = Not IsNull(DLookup("Print_ID"," LendTransactions",
strCriteria))
If blnIsRemoved Then
MsgBox MESSAGE, vbInformation, "Warning"
Cancel = True
End If
You'd do similarly for the Video_ID and Audio_ID combo boxes
That should work, but I'd point out that your Lending table is not properly
normalized. By having the L_First_Name, L_Last_Name columns in this table we
are being told that these are the names of the lender in every row in which
they lend items. So if a lender lends items to three borrowers then we'd
redundantly be told the lender's name three times. You should just have a
LenderID foreign column which references the LenderID primary key of a table
Lenders in which there is one row per lender with their names etc. Similarly
you should just have a Borrower ID referencing a Borrowers table. If lenders
can be borrowers and vice versa then you just need a single People table of
course. This could be related to Lenders and Borrowers tables in one-to-one
relationships so you could have attributes (columns) specific to lenders and
borrowers in each. This would be a Type/Sub-type model, which is aboutthe
only time you use a one-to-one relationship.
I note that your lending and return dates are in the Lending table. That's
fine if all related items in LendTransactions are lent and returned at the
same time. The former is going to be true I'd guess, but if individualitems
might be returned, legitimately or otherwise, on different dates then the
return date should be a column in LendTransactions, not in Lending.
You also should have an Authors table with primary key AuthorID and
reference this from [Print Table] etc with a foreign key AuthorID column
(remember the three instances of me!). Don't use names as keys; names can be
duplicated.
For sending emails take a look at the SendObject method in Help.
Ken Sheridan
Stafford, England
Thanks Ken. We have been working on this Inventory database for
sometime. We have linked the mainform to a subform. The Main Form
table looks like this:
Lending_ID - AutoNumber (PK)
Borrower_ID - Number
L_First_Name (Lender's First Name)
L_Last_Name
C_Date (current date)
Lending_Date
To_Be_Returned_Date
Return_Date
B_First_Name (borrower's first name)
B_Last_Name
B_email
B_phone
Position
Department
Organization
LendTransactions_ID
Lending_ID
Print_ID
Video_ID
Audio_ID
Condition_Out
Condition_I
Trans_In_Out - Data Type Yes/No Field *(if the material has been lent
out or not) *
* I thought this would be the indicator that would affect the status
on the list
(1) Print Table
These have all linked successfully. We just needed that formula you
have given us to ensure when material is lent out it doesn't show up
on the list. I think there is some redundancy with the "condition" on
both Transactions, Print, and Video. It seems to be getting quite
difficult. We also added a link to email as a friendly reminder to
bring back materials the day before they are due. Thanks so much for
your help. Any other suggestions are greatly appreciated!
Kim
Edmonton, Canada- Hide quoted text -
- Show quoted text -