0

In Access 2003, programming with VBA.

I have a list box to fill data with two columns. One column is ID and the other column is Name. I want the 4 digit format on the ID column

I try at list box' Row Source Properties

I write select sql statment like this

select format([ID],'0000'), Name from myTable

It doesn't work.

When I remove format function, it works.

I want to fill the data with the required format

2
  • By "It doesn't work", what do you mean? It shows ID without formatting. It doesn't list anything in the list box? You get an error? Commented May 12, 2011 at 19:07
  • 2
    Note, using Name as a column name is not a great idea as NAME is a reserved word in MS Access. It can cause you lots of grief later on. support.microsoft.com/kb/286335 Commented May 12, 2011 at 19:14

1 Answer 1

1

I've only got 2007 here, so it might be a version difference....

Depending on what you mean by "it doesn't work", one of my answers has to be "Yes, it does". My test form did display the formatted ID field correctly.

However, it's no longer the ID field in the control--it's now Expr1, so this does break binding. If you want your display as you described, but still want the control bound to the ID column, try this:

First modify your Row Source to be:

select ID, Format([ID],'0000') As FormattedID, [Name] As SomeName from myTable

(and while you're at it, change the name of Name if you can--I've aliased it in case you don't have control over the table design). Then set Bound Column to 1, Columns to 3 and Column Widths to 0";1";1". This will hide the bound ID but display the formatted one to the user.

Sign up to request clarification or add additional context in comments.

1 Comment

Now, i found format function in other forms works well, but it doesn't work in one form. When I removed format function in SQL statement, this form run correctly. After inserting format function in SQL statement, I got this error. <Path> is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides. (Error 3044)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.