How to limit selection of items from a combo box to once only

I have limited the list of selection from a combobox as you can see from the picture below, now all I want is that the two accounts showing in the combobox MUST NOT BE SELECTED TWICE  , in short I'm saying they must be selected once per transaction NOT TWICE.

Is the a way to use VBA to achieve that?

The combo box name is called ACCOUNTID , this combo box has only two accounts namely ( Stocks  and Work in progress)

productions-vat.png
LVL 3
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gustav BrockCIOCommented:
You could run this code in the BeforeUpdate event of the combobox:

Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone

rs.FindFirst "AccountID = '" & Me!AccountID.Value & "'"
Cancel = Not rs.NoMatch

If Cancel = True Then
    MsgBox "This Account has already been selected. Please use another."
End If

Open in new window

Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAuthor Commented:
So how do silot the account code? the two account codes are "77" & "94"which represent the primary keys, so how do i slot in the code????????

im rs As DAO.Recordset

Set rs = Me.RecordsetClone

rs.FindFirst "AccountID = '77" & Me!AccountID.Value & "'"
Cancel = Not rs.NoMatch

If Cancel = True Then
    MsgBox "This Account has already been selected. Please use another."
End If
Gustav BrockCIOCommented:
If the combobox is bound to another column than the displayed, try this:

rs.FindFirst "AccountID = '" & Me!AccountID.Column(n) & "'"
' or, for numbers:
rs.FindFirst "AccountID = " & Me!AccountID.Column(n) & ""

Open in new window

where n is the column id (from 0).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScDirectorAuthor Commented:
Thank you so much Gustav Brock , clearly and professionally you have sorted out this problem once and for all.

Many many thanks


Regards

Chris
Gustav BrockCIOCommented:
You are welcome!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.