View Full Version : Combo Box


ALANBELL1
01-07-2002, 01:38 AM
In Access 97 to put a default value in a combo box I code the following:
Me!Cmb1.DefaultValue = Me!Cmb1.ItemData(0)
and this works fine.
However when converting this database to Access 2000 this no longer works and I cannot get a default value in unless I hard code one in.This is not appropiate as the records in the combo box change daily.
Can anyone help please.Thankyou.

Alan Bell

donbettis
01-07-2002, 06:21 AM
I am not if I am understanding your Question right...

However, the way I achieve something similar to this is:

I create a query based on the table that contains my data…I add only the field that I want in my Combo...Let us say that item is FirstName...Then in the criteria field of FirstName I place Is Not Null…

I then create a hidden field on my form called say FirstName2… It’s Control Source is set to FirstName of my table…

Then I base my Combo Box on this query…

And finally I put the following code in the OnCurrent Event of the Form:

Me![Your Combo Box Name] = Me![The Name of The Hidden Field]


I am not sure if this is the right way of doing this or, if it will fit your needs however, it works for my needs…


Hope This Helps… http://www.access-programmers.co.uk/ubb/smile.gif

Don

Once Again Edited Because of typo...

[This message has been edited by donbettis (edited 01-07-2002).]

ALANBELL1
01-08-2002, 02:29 AM
Thanks for your reply Don, but what I am doing is filling the combo box with week no's and dates then depending on the current date putting a default value in the combo box.My code is something like this:

intc = Me!Cmbwk1.ListCount
For inti = 0 To intc - 1
If datyrwk = Me!Cmbwk1.Column(1, inti) Then
Me!Cmbwk1.DefaultValue = ctl.ItemData(inti)
End If
Next inti

Now this works fine in Access 97 but when I
converted this to Access 2000 it does not put the default value in the combo box even though it finds a match.Any thoughts anyone?

Regards,
Alan