Hi, jped.
OK, I get it now--sometimes takes me a while!
Since tblPurchaseOrder was on the many side of a one-to-many with
Disbursements, Access would not let you enter a child record without
establishing to which parent in Disbursements it should belong.
Not all PurchaseOrder records will have a disbursement associated with it;
only those of the certain type. One solution is the one you implemented. If
you'd like to enforce referential integrity, every record must have a
Disbursement value, so I suggest adding a record to the Disbursement table
with the description "No Disbursement", and setting the value in the payment
combo box' AfterUpdate event.
I also realized that it's possible for the user to change the payment type,
so you should set the visibility status either way, just like as in the On
Current event:
If YourFirstComboBox = YourValue Then
Me!YourSecondComboBox.Visible = True
Me!YourTextBox.Visible = True
Else
Me!YourSecondComboBox.Visible = False
Me!YourTextBox.Visible = False
Me!YourSecondComboBox = YourNoDisbursementID
End If
One other condition that could occur is that your user picks the payment
type that requires a disbursement, and they do not enter a value, which would
violate referential integrity. To avoid Access' cryptic message, intercept
it with the form's BeforeUpdate event. If you wish to permit the user to
enter no disbursement in this case, show a message box. If they confirm no
disbursement, you can set the value to the ID associated with "No
Disbursement" and continue, otherwise, cancel and return him to the combo box:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim intRetVal As Integer
If Nz([cboDisbursement]) = 0 Then
intRetVal = MsgBox("You did not enter a disbursement. Press Cancel
to enter a disbursement or OK to continue.", vbOKCancel)
If intRetVal = vbCancel Then
Cancel = True
Me!cboDisbursement.SetFocus
Else
' Set to "No Disbursement"
Me!cboDisbursement = YourNoDisbursementID
End If
End If
End Sub
Sprinks
jped said:
I'm sorry, the hidden combo box gets its values from tblDisbursements, but
the value that is selected is stored in Disbursements in the
tblPurchaseOrders (main table). These controls are on the main form, not the
subform.
I am trying to store the value selected from the Disbursement combo box,
PaymentMethod combo box, as well as some other general text boxes on the main
form, which all work correctly. The hidden Disbursement combo box is a new
addition to the database.
Disbursement combo box (hidden)
ControlSource= DisbursementID (This is the ID number associated with the
Disbursement value from the combo box and is being store in the PurchaseOrder
table. The field in tblPurchaseOrder is called DisbursementID)
RowSource= SELECT tblDisbursement.DisbursementID, tblDisbursement.Disbursement
FROM tblDisbursement;
(It's selecting the values from tblDisbursement, which I'm sure you can see)
BoundColumn= 1
Do you need more info? Thank you so much for helping me out!