?
Solved

Problems with default value in MS Access 2007

Posted on 2009-04-22
10
Medium Priority
?
370 Views
Last Modified: 2013-11-28
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
Comment
Question by:BobHavertyComh
  • 5
  • 5
10 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 24205850
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
 
LVL 9

Author Comment

by:BobHavertyComh
ID: 24206005
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 24206104
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Author Comment

by:BobHavertyComh
ID: 24206707
No, the article says not to put brackets around ItemData, but Access adds these and then tells me it's an invalid expression
0
 
LVL 9

Author Comment

by:BobHavertyComh
ID: 24206721
It flags the expression when you go to save the table and it won't let you save it.
0
 
LVL 9

Author Comment

by:BobHavertyComh
ID: 24206799
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 24206935
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
 
LVL 9

Author Comment

by:BobHavertyComh
ID: 24207039
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
 
LVL 65

Accepted Solution

by:
rockiroads earned 2000 total points
ID: 24207190
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 24207194
I meant look in design view
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question