Combo box values for existing and new records

andis.cirulis

New member
Local time
Today, 17:54
Joined
May 18, 2010
Messages
2
Hello,
I don't really know how to formulate question, so I will try to
explain problem shortly:
I have created small invoicing application in Access 2007 for renting
business - there is table of customers, table of invoices and table of
devices we offer for rent (there is one type of devices, total number
- around 10)
There is form for entering new customers and that form contains combo
box, which is lookup to devices table - so user can pick one of
devices.
Everything works so far.
I wanted to introduce new feature - when adding new customer, user can
choose only from those devices which are not rented away. So I created
subquery to limit values of combo box.
Query looks like this:
Code:
SELECT Koncentratori.ID, Koncentratori.AccountingNumber 
FROM Koncentratori 
WHERE (((Koncentratori.ID) Not In (SELECT customers.ConcentratorID 
FROM customers WHERE (((customers.agreementActive)=Yes)); ))) 
ORDER BY Koncentratori.AccountingNumber;
Koncentratori (Concentrators) is the mentioned table of devices, rest
should be obvious.
So far so good.
But here comes the problem - after using this subquery, new record can
be added nicely and combo box contains only those devices, which are
not rented away. However for existing customers combo box does not
show current value - as it is in conflict with that subquery.
I am not sure how to overcome this problem, thanks for any advice!
Br,
Andis
 
Hello and welcome to the forums!

I see the difference between your two situations is one if for a new record and the other is not. I would suggest performing a logical check and and depending on the outcome of that check to modify the control source of your combo box. This can be done by using the NewRecord property.

For instance, on the OnLoad event of your form you could try ...

Code:
If Me.NewRecord Then
   Me.cmbComboName.ControlSource = 'something
Else
   Me.cmbComboName.ControlSource = 'something else
End If

There might be alternatives out there but this is the way I have handled it in the past.

HTH,
-dK
 
Thanks!!

I used onCurrent, instead of onLoad event handler, since I have [New record] button added on form, and it does not reload the form. Otherwise, this works as esxpected.

I am not sure, if this is the best scenario, either, (specially for larger volumes of data), but it does not matter in my case.

Regards,
Andis
 
Great! Aye, the OnCurrent works nicely considering how you are operating there. I've not seen issues with 16k+ (about 20 fields) records using this method so you should be in clear.

Glad I could help and good luck!
-dK
 

Users who are viewing this thread

Back
Top Bottom