Hi.
I'm using Access 2010 x86
I'm trying to create a Multi Value Field in a table using DAO, with the following code: - Sub Test1()
-
Dim db As dao.Database, tdf As dao.TableDef, fld As Field
-
Set db = CurrentDb
-
Set tdf = db.TableDefs("Contacts")
-
With tdf
-
-
Set fld = .CreateField("New", dbText, 255)
-
-
.Fields.Append fld
-
-
-
fld.Properties.Append .CreateProperty("DisplayControl", dbInteger, acComboBox)
-
fld.Properties.Append ..CreateProperty("AllowMultipleValues", dbBoolean, True)
-
Set fld = Nothing
-
-
End With
-
Set tdf = Nothing
-
Set db = Nothing
-
-
End Sub
It works well, but the only thing is that when later I open the table, I get the message:
"You have changed the "New: lookup column to store multiple values. You will not be able to undo this change once you save the table", each time I open the table, no matter if I save it or not.
Do you know how can I bypass/avoid this message?
I apologize for taking such a late look at Thread, but when I finally did, I took a keen interest in it. I do believe that I got it working exactly as it should, but I will let you be the judge of that. For the Row Source of the Multi-Valued Field I used the [Last Name] Field of the Employees Table only for the sake of brevity and simplicity, modify as needed. Let us know how you make out. -
Dim db As DAO.Database
-
Dim tdf As DAO.TableDef
-
Dim fld As Field
-
-
Set db = CurrentDb
-
Set tdf = db.TableDefs("Contacts")
-
-
With tdf
-
Set fld = .CreateField("New", dbComplexText, 255)
-
.Fields.Append fld
-
With fld
-
.Properties.Append .CreateProperty("AllowMultipleValues", dbBoolean, True)
-
.Properties.Append .CreateProperty("DisplayControl", dbInteger, acComboBox)
-
.Properties.Append .CreateProperty("RowSourceType", dbText, "Table/Query")
-
.Properties.Append .CreateProperty("RowSource", dbText, _
-
"SELECT [Last Name] FROM Employees")
-
.Properties.Append .CreateProperty("BoundColumn", dbInteger, 1)
-
.Properties.Append .CreateProperty("ColumnCount", dbInteger, 1)
-
.Properties.Append .CreateProperty("ColumnHeads", dbBoolean, False)
-
.Properties.Append .CreateProperty("ListRows", dbInteger, 16)
-
.Properties.Append .CreateProperty("LimitToList", dbBoolean, True)
-
End With
-
Set fld = Nothing
-
End With
-
-
Set tdf = Nothing
-
Set db = Nothing
17 4173
FYI, did you notice the 2 "." in your code? Is that a mistake? - fld.Properties.Append ..CreateProperty
On the same line, check this out: - expression .CreateProperty(Name, Type, Value, DDL)
If DDL is True, users can't change or delete this Property object unless they have dbSecWriteDef permission.
This option is now ruled out.
It's a typo here, in the code I got it right.
I made the DDL false, and still get the same message after entering the altered table.
this is my current code, after your suggestion: - Sub Test1()
-
Dim db As dao.Database, tdf As dao.TableDef, fld As Field
-
Set db = CurrentDb
-
Set tdf = db.TableDefs("Contacts")
-
With tdf
-
-
Set fld = .CreateField("New3", dbText, 255)
-
-
.Fields.Append fld
-
-
-
fld.Properties.Append .CreateProperty("DisplayControl", dbInteger, acComboBox)
-
fld.Properties.Append .CreateProperty("RowSourceType", dbText, "Table/Query")
-
fld.Properties.Append .CreateProperty("RowSource", dbText, "SELECT Slownik.Sprzedawca FROM Slownik WHERE (((Slownik.Sprzedawca) Is Not Null));")
-
fld.Properties.Append .CreateProperty("BoundColumn", dbInteger, 1)
-
fld.Properties.Append .CreateProperty("ColumnCount", dbInteger, 1)
-
fld.Properties.Append .CreateProperty("ColumnHeads", dbBoolean, False)
-
fld.Properties.Append .CreateProperty("ListRows", dbInteger, 16)
-
fld.Properties.Append .CreateProperty("LimitToList", dbBoolean, True)
-
fld.Properties.Append .CreateProperty("AllowValueListEdits", dbBoolean, False)
-
fld.Properties.Append .CreateProperty("ShowOnlyRowSourceValues", dbBoolean, False)
-
fld.Properties.Append .CreateProperty("AllowMultipleValues", dbBoolean, True, False)
-
Set fld = Nothing
-
-
End With
-
Set tdf = Nothing
-
Set db = Nothing
-
-
End Sub
you can try to run it, and see (just need to create "Contacts" table
notice that in the AllowMultipleValues property I choose DDL as false.
When you say you "open the table" does that refer to viewing the recordset from double clicking the Table object on the Access Objects list, or does it occur when a form opens using the table from data?
Also, I'm not sure if this matters but I would move the
outside of the
It occurs only when i view the recordset from double clicking the Table object on the Access Objects lists.
Also, even though viewing the table's fields properties through Access Objects list shows Allow Multiple Values property as True, it only presents a regular Combo Box in it's display control (both from a form or from table view) and not the Multi Combo Box that it suppose to present.
While MS Access does support multi-value fields, it is not considered a best practice for proper database design. It would be better to create a new table and then link them using a Primary Key - Foreign Key pair. Not only would you totally get around your current troubles, but you would also save yourself from headaches further down the line. See Database Normalization and Table Structures for more information on proper database design.
And it is very easy to do it using the separate table method.
Well, thanks so much for your suggestion, Seth.
I've used the multi-value fields, and although it is not considered as a best practice, they served me well.
Also, the give my users the ability to multi-select values from combo-boxes, which is very UI-convinient, and is possible only through Multi Value Fields.
mcupito, I moved it outside With, you are right,
but the problem still remains...
There is probably some table property that needs to be applied in order for this to work, I just don't know which one.
At this point, it might be useful to see what methods you tried when you say "whether I save it..."
From the message it sounds like it is not being saved correctly. I could be wrong though.
When Access asks me: "You have changed the "New: lookup column to store multiple values. You will not be able to undo this change once you save the table"
"Do you want to change "New" lookup column to store multiple values?"
Either I choose "yes" or "no", the result is the same, that column also appears to be multivalued doesn't allow choosing multiple values.
I apologize for taking such a late look at Thread, but when I finally did, I took a keen interest in it. I do believe that I got it working exactly as it should, but I will let you be the judge of that. For the Row Source of the Multi-Valued Field I used the [Last Name] Field of the Employees Table only for the sake of brevity and simplicity, modify as needed. Let us know how you make out. -
Dim db As DAO.Database
-
Dim tdf As DAO.TableDef
-
Dim fld As Field
-
-
Set db = CurrentDb
-
Set tdf = db.TableDefs("Contacts")
-
-
With tdf
-
Set fld = .CreateField("New", dbComplexText, 255)
-
.Fields.Append fld
-
With fld
-
.Properties.Append .CreateProperty("AllowMultipleValues", dbBoolean, True)
-
.Properties.Append .CreateProperty("DisplayControl", dbInteger, acComboBox)
-
.Properties.Append .CreateProperty("RowSourceType", dbText, "Table/Query")
-
.Properties.Append .CreateProperty("RowSource", dbText, _
-
"SELECT [Last Name] FROM Employees")
-
.Properties.Append .CreateProperty("BoundColumn", dbInteger, 1)
-
.Properties.Append .CreateProperty("ColumnCount", dbInteger, 1)
-
.Properties.Append .CreateProperty("ColumnHeads", dbBoolean, False)
-
.Properties.Append .CreateProperty("ListRows", dbInteger, 16)
-
.Properties.Append .CreateProperty("LimitToList", dbBoolean, True)
-
End With
-
Set fld = Nothing
-
End With
-
-
Set tdf = Nothing
-
Set db = Nothing
ADezii, I appreciate your input and help.
Also I appreciate mcupito and Seth Shrock's time.
:)) !!
It works,
with dbComplexText / dbComplexLong / etc..
How wonderful,
thanks.
p.s.
What is dbComplex?
@MichaelR:
Glad we got it working for you. In the case of dbComplexText, it is a Multi-value, variable width, Complex DAO Data Type used specifically in Multi-Value Fields. As for the other Complex Data Type variations, the same concept would apply.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Lars Netzel |
last post by:
Hi
I fill an adapter from access and one of the columns are a DateTime type.
in access the format is like this "2005-01-20 08:09:01" but when I get it to
show in a Datagrid boudn from the...
|
by: Hugh Middity2 |
last post by:
Hello, is there a parameter value field in access that can be passed between queries, forms and reports?
For example, we have two companies both selling the same products. To extract data we have to...
|
by: notsosavy |
last post by:
On a form, I would like to have a field that I can enter in an employee's last name, click on a button, and it would search the Employee table for that last name.
If it doesn't exist, an error...
|
by: beemomo |
last post by:
Hi everyone there, i am facing the problem with using the SQL condition --LIKE in a multi value field of my access 07 table.
I have a multi value field which store a number of keywords for a...
|
by: stoogots2 |
last post by:
I have a field named sList in a Sql Server database table. The field has multiple delimited values (delimited with "|"). Example could be "1|2|3|4|5". I have a view with several fields (including...
|
by: jim |
last post by:
Each night, a scheduled task copies certain information from an MS
Access db to a MySQL db that serves as a data warehouse. I would like
to begin replicating multi-value fields from Access to...
|
by: lupis |
last post by:
I am pretty new to vba. This is what I am trying to achieve.
I have a form that onload displays all records in a form.
I also have a searchbox with a button that should be able to take multiple...
|
by: amy1 |
last post by:
Hello everyone,
I'm new here and new to Access2007 as well!
I have a multi-value field in a form, and would like to calculate the total of the selected values in this field and place the...
|
by: jaad |
last post by:
how do you reference a single value field to a multi-value field?
I sometime use a macro in form1 to open form 2 containing the same ID
example:
Open form: WorkOrder
where condition: ="="...
|
by: WaqasAnsari |
last post by:
This is what I am working on. When patients count is 0, it works, but when it is increased, suppose 1, it gives an error: "An UPDATE or DELETE query doesn't contain Multi Value Field." What's the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| | |