Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box Default Value Problem

Status
Not open for further replies.

fneily

Instructor
Apr 5, 2002
2,538
US
I have a table with a field that has Data type Text that looks like this;
ShaNumber
MPM-8
PPM-23
5137
15045
46005
etc.
The first two entries are the only ones with text. The rest are numbers.
I created a combobox called shacombo with rowsource of:
Select [SHANumber] From [MMC_To_SHANumber_Table] Where [MMCNumber] = Forms![Modal_Clearance_Update_Form]![MMCNumber] Order By [SHANumber];
This works fine.
I now want to change the rowsourse on current record with
Me![shacombo].Requery
Me![shacombo].DefaultValue = Me![shacombo].ItemData(0)

The DefaultValue for the first two entries return #Name. However, they are in the dropdown list. The numbers work fine.
I noticed that the combobox properties has an entry in the Decimal option(auto) indicating, I think, that the combobox expects numerics. Yet the combobox is based on a text field. For some reason when ItemData(0) is text, it returns an error.
Any ideas.
Thanks.
 
I checked the Immediate Pane in VBA and sure enough ItemData(0) is MPM-8. MPM-8 also shows up in the Default box of the property sheet. Yet the combobox shows #Name?. I found in the Access 2000 Bible book of Prague and Irwin that Access determines the "data type" of the combobox from the RowSource. But all the fields in my RowSource are text (even though they say number). Still perplexed.
 
I added the following code after the Me![shacombo].Requery statement and now it works fine. I used the value function because I know none of the "regular" numbers would be lower than 100. I could have also tested for a "alphabetic". Also notice that I had to place the ItemData(0) in quotes. I guess when you make an unbound combobox and have mixed data in a column, it assumes a numeric entry. But I can't find any documentation on this and Microsoft wants $25 for the answer. Why do I have mixed data in a column? It's a government job, I'm working on. They used numerics for tracking on 3000 records except these two.

If Val(Me![shacombo].ItemData(0)) < 100 Then
Me![shacombo].DefaultValue = "'" & Me![shacombo].ItemData(0) & "'"
Else
Me![shacombo].DefaultValue = Me![shacombo].ItemData(0)
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top