SteveL13
asked on
How limit list selections if record is not a new record
On a form I have a single select listbox. The SQL behind the listbox is:
SELECT tblLoadsHeader.LoadRecordI D, tblLoadsHeader.ContractNum ber
FROM tblLoadsHeader
ORDER BY tblLoadsHeader.[ContractNu mber];
Which display all ContractNumbers in tblLoadsHeader.
This is fine for a new record. But If I'm viewing an existing record I only want to see the ContractNumber in the listbox that was selected when the record was created. Note: The contractnumber IS being stored in the table that is the record source for the form.
How can I make the listbox only show that record?
SELECT tblLoadsHeader.LoadRecordI
FROM tblLoadsHeader
ORDER BY tblLoadsHeader.[ContractNu
Which display all ContractNumbers in tblLoadsHeader.
This is fine for a new record. But If I'm viewing an existing record I only want to see the ContractNumber in the listbox that was selected when the record was created. Note: The contractnumber IS being stored in the table that is the record source for the form.
How can I make the listbox only show that record?
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Pat, I appreciate your suggestion and will lock it if is not a new record. But I still want to have it display whatever was selected when the record was created.
John, your suggestion may work but I need to have it as VBA code. I don't know how to convert it.
John, your suggestion may work but I need to have it as VBA code. I don't know how to convert it.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
In the Current event of the form:
If Me.NewRecord = True Then
Me.cboContractNumber.Locke
Else
Me.cboContractNumber. Locked = True
End If
This will still allow you to change the contract number until you leave the record. If you want to lock the combo as soon as the record is saved, then in the AfterUpdate event of the form, add:
Me.cboContractNumber.Locke