• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

Problems with default value in MS Access 2007

I have create a DLookup for a list box field where I manually typed the values, so it's a static choice list. I want to set the default choice to be the first value I typed in or the first one that shows up on the list. According to Microsoft, this is the way you do that. [control name].ItemData(0). The problem is that Access keeps adding brackets around Item.Data when I leave the default value field. I watch it happen right in front of my eyes, and then, Access rejects the formula as invalid when i go to save the table in Design view and it rejects a formula with brackets that I never added and instead it added for some unknown reason. To make sure I was using the right control name, I went to my form, right clicked the control and got it's properties and read it's name. It's the same name as it's field name, so I think I'm using the right control name. Has anybody else seen this weirdness?
0
BobHavertyComh
Asked:
BobHavertyComh
  • 5
  • 5
1 Solution
 
rockiroadsCommented:
It needs brackets cos it is returning a value

so how have you done this? you could do it in vba like this

me.mylistbox.value = me.mylistbox.itemdata(0)

0
 
BobHavertyComhAuthor Commented:
It doesn't need brackets around ItemData according to this article, but Access keeps adding them and then flagging it as a failed equation that Access itself is creating by adding the brackets. Check out the section for setting the default value form a list item and combo box

http://office.microsoft.com/en-us/access/HA100964511033.aspx
0
 
rockiroadsCommented:
I gave it a test and no issues yet

Produced something like this

[List0].[itemdata](0)

Nothing wrong with square brackets as access uses that to wrap object names

is this what you got?
in your question u put down item.data but Im assuming that is a typo
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
BobHavertyComhAuthor Commented:
No, the article says not to put brackets around ItemData, but Access adds these and then tells me it's an invalid expression
0
 
BobHavertyComhAuthor Commented:
It flags the expression when you go to save the table and it won't let you save it.
0
 
BobHavertyComhAuthor Commented:
Error message when trying to save the table is:

Unknown function '[Short Test 1 pt 8v].[ItemData]' in validation expression or default value on 'RX Tests.Short Test 1 pt 8v'
0
 
rockiroadsCommented:
save the table? My apologies, I thought you was doing this for a form

What you are attempting to do is on a form only,
0
 
BobHavertyComhAuthor Commented:
Added the code to the appropriate list box control on the form and it let me save it. However, the dropdown doesn't have the default value automatically selected, and, even stranger, when it datasheet view, once I select a value, it submits the entire record. So there's something I don't understand about how default values work with a list box with static choices.
0
 
rockiroadsCommented:
ok, lets look at your listbox

what is the rowsource for this listbox? it will be values delimited by a semi colon, does it?
rowsource type should be value list
0
 
rockiroadsCommented:
I meant look in design view
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now