473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

CreateProperty

OK, so I've been playing with this for too long, not getting it to work.
Seems pretty simple, and I'm sure I'm just klutzing some syntax, but...

I need to update the description property of queries via code. I know that
the property doesn't exist unless it's been set, because it's an Access
property tagged onto a Jet object. I've searched a bunch on google and read
the help topic about four times (which is not an assertion that the answer's
not in there). I've checked references and not noticed anything that would
hold me back, but maybe I'm missing something there.
I cribbed some test code that works just fine in 97 but won't work in 2002,
which is where I need it. This works for a query that has never had a
description. I haven't run it on one that does, because I'm just trying to
get this down first. When I run this:

Sub setTheDesc()
Dim MyQuery As QueryDef
Dim myDB As Database
Dim myProperty As Property
Dim VarValue As Variant

VarValue = "works here"
Set myDB = CurrentDb
Set MyQuery = myDB.QueryDefs("qry3")
Set myProperty = MyQuery.CreateProperty("Description", dbText, VarValue)
Call MyQuery.Properties.Append(myProperty)

End Sub

I get a type mismatch error on the "Set myProperty..." line. The same exact
code works fine in 97. What do I need to do to get this to work in 2002?

Thanks for any help.

Jeremy
--
Jeremy Wallace
AlphaBet City Dataworks
http://www.ABCDataworks.com

Nov 12 '05 #1
4 15489
Jeremy,
1 Make sure you have a reference to DAO
2 Change your declarations as follows

Dim MyQuery As DAO.QueryDef
Dim myDB As DAO.Database
Dim myProperty As DAO.Property
Dim VarValue As Variant

Terry

"Jeremy Wallace" <ab**********@AlphaBetCityDataworks.com> wrote in message
news:YP********************@speakeasy.net...
OK, so I've been playing with this for too long, not getting it to work.
Seems pretty simple, and I'm sure I'm just klutzing some syntax, but...

I need to update the description property of queries via code. I know that
the property doesn't exist unless it's been set, because it's an Access
property tagged onto a Jet object. I've searched a bunch on google and read the help topic about four times (which is not an assertion that the answer's not in there). I've checked references and not noticed anything that would
hold me back, but maybe I'm missing something there.
I cribbed some test code that works just fine in 97 but won't work in 2002, which is where I need it. This works for a query that has never had a
description. I haven't run it on one that does, because I'm just trying to
get this down first. When I run this:

Sub setTheDesc()
Dim MyQuery As QueryDef
Dim myDB As Database
Dim myProperty As Property
Dim VarValue As Variant

VarValue = "works here"
Set myDB = CurrentDb
Set MyQuery = myDB.QueryDefs("qry3")
Set myProperty = MyQuery.CreateProperty("Description", dbText, VarValue)
Call MyQuery.Properties.Append(myProperty)

End Sub

I get a type mismatch error on the "Set myProperty..." line. The same exact code works fine in 97. What do I need to do to get this to work in 2002?

Thanks for any help.

Jeremy
--
Jeremy Wallace
AlphaBet City Dataworks
http://www.ABCDataworks.com

Nov 12 '05 #2
Terry,

Duh. I did have the dao reference, and had put the DAO.s in before the
querydef and database, but somehow not the property. So I've fixed that.
Thanks.

But now I only get one line further. On the last line:

Call MyQuery.Properties.Append(myProperty)

I get error 3367, telling me that it can't be appended because "An object
with that name already exists in the collection." Seems odd. The queries I
test this on are all brand new, with nothing ever having been in the
"Description" property.

OOOOOooooooh.

Ouch. And sorry for wasting your time.

Seems all the posts I read about this property not existing until there's
something in it do not apply to Access 2002.

All I needed to do was this:

CurrentDb.QueryDefs("qry9").Properties("Descriptio n") = "blah"

(or any one of a zillion other ways to reference that property, which is
already there) Oh that hurts. But at least the code will be easy to write.

Thanks again.

Jeremy
--
Jeremy Wallace
AlphaBet City Dataworks
http://www.ABCDataworks.com
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:bo**********@newsreaderg1.core.theplanet.net. ..
Jeremy,
1 Make sure you have a reference to DAO
2 Change your declarations as follows

Dim MyQuery As DAO.QueryDef
Dim myDB As DAO.Database
Dim myProperty As DAO.Property
Dim VarValue As Variant

Terry

"Jeremy Wallace" <ab**********@AlphaBetCityDataworks.com> wrote in message
news:YP********************@speakeasy.net...
OK, so I've been playing with this for too long, not getting it to work.
Seems pretty simple, and I'm sure I'm just klutzing some syntax, but...

I need to update the description property of queries via code. I know that the property doesn't exist unless it's been set, because it's an Access
property tagged onto a Jet object. I've searched a bunch on google and

read
the help topic about four times (which is not an assertion that the

answer's
not in there). I've checked references and not noticed anything that would hold me back, but maybe I'm missing something there.
I cribbed some test code that works just fine in 97 but won't work in

2002,
which is where I need it. This works for a query that has never had a
description. I haven't run it on one that does, because I'm just trying to get this down first. When I run this:

Sub setTheDesc()
Dim MyQuery As QueryDef
Dim myDB As Database
Dim myProperty As Property
Dim VarValue As Variant

VarValue = "works here"
Set myDB = CurrentDb
Set MyQuery = myDB.QueryDefs("qry3")
Set myProperty = MyQuery.CreateProperty("Description", dbText, VarValue)
Call MyQuery.Properties.Append(myProperty)

End Sub

I get a type mismatch error on the "Set myProperty..." line. The same

exact
code works fine in 97. What do I need to do to get this to work in 2002?

Thanks for any help.

Jeremy
--
Jeremy Wallace
AlphaBet City Dataworks
http://www.ABCDataworks.com


Nov 12 '05 #3
Huh. Can't see my previous post, but I did just post something saying that I
didn't have to do any of this, all I needed to do was:
CurrentDb.QueryDefs("qry9").Properties("Descriptio n") = "blah"

Well it turns out that works in an Access 2002 database, but not in an
Access 2000 database opened with Access 2002. I don't have 2k, so I can't
test that. In the Access 2000 database, it did, of course, work to just
disambiguate the declarations.

Thanks, once again.

Jeremy

--
Jeremy Wallace
AlphaBet City Dataworks
http://www.ABCDataworks.com
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:bo**********@newsreaderg1.core.theplanet.net. ..
Jeremy,
1 Make sure you have a reference to DAO
2 Change your declarations as follows

Dim MyQuery As DAO.QueryDef
Dim myDB As DAO.Database
Dim myProperty As DAO.Property
Dim VarValue As Variant

Terry

"Jeremy Wallace" <ab**********@AlphaBetCityDataworks.com> wrote in message
news:YP********************@speakeasy.net...
OK, so I've been playing with this for too long, not getting it to work.
Seems pretty simple, and I'm sure I'm just klutzing some syntax, but...

I need to update the description property of queries via code. I know that the property doesn't exist unless it's been set, because it's an Access
property tagged onto a Jet object. I've searched a bunch on google and

read
the help topic about four times (which is not an assertion that the

answer's
not in there). I've checked references and not noticed anything that would hold me back, but maybe I'm missing something there.
I cribbed some test code that works just fine in 97 but won't work in

2002,
which is where I need it. This works for a query that has never had a
description. I haven't run it on one that does, because I'm just trying to get this down first. When I run this:

Sub setTheDesc()
Dim MyQuery As QueryDef
Dim myDB As Database
Dim myProperty As Property
Dim VarValue As Variant

VarValue = "works here"
Set myDB = CurrentDb
Set MyQuery = myDB.QueryDefs("qry3")
Set myProperty = MyQuery.CreateProperty("Description", dbText, VarValue)
Call MyQuery.Properties.Append(myProperty)

End Sub

I get a type mismatch error on the "Set myProperty..." line. The same

exact
code works fine in 97. What do I need to do to get this to work in 2002?

Thanks for any help.

Jeremy
--
Jeremy Wallace
AlphaBet City Dataworks
http://www.ABCDataworks.com



Nov 12 '05 #4
Jeremy,
re:-
CurrentDb.QueryDefs("qry9").Properties("Descriptio n") = "blah"

I cannot reproduce the behaviour that you see in Access2002.

The following function certainly works (and should work in all versions)
' ************************************
' Code Start
' ************************************
Option Explicit

Public Enum ERR_RETS
erObjTypeNotSupported = 1100 + vbObjectError
End Enum
' ************************************
'

Function SetProperty( _
ObjType As AcObjectType, _
ObjName As String, _
PropName As String, _
PropValue, _
PropType As DAO.DataTypeEnum, _
Optional DDL As Boolean = False _
)
Dim loObj As Object
Dim loDB As DAO.Database
Dim loProp As DAO.Property

On Error GoTo SetProperty_Err

Const ERR_MSG_OBJ_TYPE_NOT_SUPPORTED = "The object type is not supported"

Set loDB = CurrentDb

Select Case ObjType
Case acReport
Set loObj = loDB.Containers("Reports").Documents(ObjName)
Case acQuery
Set loObj = loDB.QueryDefs(ObjName)
Case acModule
Set loObj = loDB.Containers("Modules").Documents(ObjName)
Case acMacro
Set loObj = loDB.Containers("Scripts").Documents(ObjName)
Case acForm
Set loObj = loDB.Containers("Forms").Documents(ObjName)
Case acTable
Set loObj = loDB.TableDefs(ObjName)
Case Else
Err.Raise erObjTypeNotSupported, , ERR_MSG_OBJ_TYPE_NOT_SUPPORTED
End Select

Set loProp = loObj.Properties(PropName)
loProp.Value = PropValue
SetProperty_End:
On Error Resume Next
Set loProp = Nothing
Set loObj = Nothing
Set loDB = Nothing
Exit Function
SetProperty_Err:
Select Case Err
Case 3270 ' Prop not found
Set loProp = loObj.CreateProperty(PropName, PropType, PropValue, DDL)
loObj.Properties.Append loProp
Case Else
With Err
MsgBox .Number & ": " & .Description
End With
End Select
Resume SetProperty_End
End Function

' ************************************
' Code End
' ************************************

Sample calls
To not set the DDL option
------------------------------
Call SetProperty(acQuery, "Query1", "Description", "Aha", dbText, False)
Or
Call SetProperty(acQuery, "Query1", "Description", "Aha", dbText)

To set the DDL option
--------------------------
Call SetProperty(acQuery, "Query1", "Description", "Aha", dbText, True)
Terry
"Jeremy Wallace" <ab**********@AlphaBetCityDataworks.com> wrote in message
news:n5********************@speakeasy.net...
Terry,

Duh. I did have the dao reference, and had put the DAO.s in before the
querydef and database, but somehow not the property. So I've fixed that.
Thanks.

But now I only get one line further. On the last line:

Call MyQuery.Properties.Append(myProperty)

I get error 3367, telling me that it can't be appended because "An object
with that name already exists in the collection." Seems odd. The queries I
test this on are all brand new, with nothing ever having been in the
"Description" property.

OOOOOooooooh.

Ouch. And sorry for wasting your time.

Seems all the posts I read about this property not existing until there's
something in it do not apply to Access 2002.

All I needed to do was this:

CurrentDb.QueryDefs("qry9").Properties("Descriptio n") = "blah"

(or any one of a zillion other ways to reference that property, which is
already there) Oh that hurts. But at least the code will be easy to write.

Thanks again.

Jeremy
--
Jeremy Wallace
AlphaBet City Dataworks
http://www.ABCDataworks.com
"Terry Kreft" <te*********@mps.co.uk> wrote in message
news:bo**********@newsreaderg1.core.theplanet.net. ..
Jeremy,
1 Make sure you have a reference to DAO
2 Change your declarations as follows

Dim MyQuery As DAO.QueryDef
Dim myDB As DAO.Database
Dim myProperty As DAO.Property
Dim VarValue As Variant

Terry

"Jeremy Wallace" <ab**********@AlphaBetCityDataworks.com> wrote in message
news:YP********************@speakeasy.net...
OK, so I've been playing with this for too long, not getting it to work. Seems pretty simple, and I'm sure I'm just klutzing some syntax, but...
I need to update the description property of queries via code. I know
that the property doesn't exist unless it's been set, because it's an Access property tagged onto a Jet object. I've searched a bunch on google and

read
the help topic about four times (which is not an assertion that the

answer's
not in there). I've checked references and not noticed anything that would hold me back, but maybe I'm missing something there.
I cribbed some test code that works just fine in 97 but won't work in

2002,
which is where I need it. This works for a query that has never had a
description. I haven't run it on one that does, because I'm just trying to
get this down first. When I run this:

Sub setTheDesc()
Dim MyQuery As QueryDef
Dim myDB As Database
Dim myProperty As Property
Dim VarValue As Variant

VarValue = "works here"
Set myDB = CurrentDb
Set MyQuery = myDB.QueryDefs("qry3")
Set myProperty = MyQuery.CreateProperty("Description", dbText,

VarValue) Call MyQuery.Properties.Append(myProperty)

End Sub

I get a type mismatch error on the "Set myProperty..." line. The same

exact
code works fine in 97. What do I need to do to get this to work in 2002?
Thanks for any help.

Jeremy
--
Jeremy Wallace
AlphaBet City Dataworks
http://www.ABCDataworks.com



Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Farek | last post by:
(If Im posting in the wrong place concerning COM+ and .NET plz redirect me.) Hello all, Im writing a COM+ in VB.NET that is suppose to be able to set/get an address(String value). I've made...
1
by: mahnovetsky | last post by:
Does anybody know of a way to set the format property for a date field in VBA?? I need to set the property to medium so I can display display aussie dates on a graph.. Here is what Im doing: ...
3
by: Adonis Walmsley-McCarthy | last post by:
Dear all, Does anybody know how to disable the bypass key ("SHIFT") which is used at startup? Thanks in advance, Adonis.
2
by: Wayne | last post by:
The following which is driving me nuts has occurred in 2 of my databases. Both databases were written in Access 2003 and then converted back to Access 2000 format. I've done this so I can create an...
6
by: Richard | last post by:
Hi, I have posted this question on another site but had no luck so far. Sorry about multiposting to those who have seen it. I wish to add the field captions programmatically to the fields...
12
by: smiler2505 | last post by:
I have a database, where I need to create a table if it doesn't exist. This is my code at the moment: Sub CreateCwS() Dim daotbl As DAO.TableDef If Not daotbl.Name =...
1
by: smiler2505 | last post by:
I know it's a strange request to want to use a combobox in a table rather than a form, but if it's possible it would be good. I know there is a ComboBox object, but all the useful references such...
42
by: smiler2505 | last post by:
I have a situation where there may be no table for a form; on error, the table is rebuilt and all is good; except to open the form, I have to click the form again. I tried DoCmd.OpenForm...
3
by: chris | last post by:
Hi I have a simple split db, that I want to create a backend table with Fields, PK, Indexes and Formats. The problem I am getting is the Error No 3219 from this line of code:-...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.