473,388 Members | 1,207 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,388 software developers and data experts.

Error '3270', Property not found, when setting Properties!ColumnWidth

Greetings.

I have VBA code running from a combobox's AfterUpdate event which sets a querydef to a particular SQL statement based on the selection. Reason: rather than saving a bunch of queries, I just have one called "qry_reporting_all" and simply change the QueryDef through VBA. Works like a charm.

Now, for aesthetic reasons, I wanted to set the query's columns for each field to 2 inches (2880 twips) wide--per my data, 2 inches looks good on the screen. So, I found some code to loop through all the fields in the query (which vary from SQL statement to SQL statement), and set those column widths. See below.

Expand|Select|Wrap|Line Numbers
  1.     Dim dbo As DAO.Database
  2.     Dim qdf As DAO.QueryDef
  3.     Dim fld As DAO.Field
  4.     Dim wid As DAO.Property
  5.     Dim strSQL As String
  6.     Dim myField As String
  7.  
  8.  
  9. strSQL = "SELECT tbl_calendar.SiteName, tbl_calendar.EventName, Count(tbl_calendar.FullName) AS EventCount " & _
  10.                         "From tbl_calendar " & _
  11.                         "GROUP BY tbl_calendar.SiteName, tbl_calendar.EventName;"    
  12.     Set dbo = CurrentDb()
  13.     Set qdf = dbo.QueryDefs("qry_reporting_all")
  14.     qdf.sql = strSQL
  15.     'set column widths
  16.     For Each fld In qdf.Fields
  17.         myField = fld.Name
  18.         Set fld = qdf.Fields(myField)
  19.         Set wid = fld.Properties!ColumnWidth  '<--Errors
  20.         wid = 2880
  21.     Next
  22.  
  23.  
  24.  
This works for fields "SiteName" and "EventName", but when it gets to field name "EventCount", it throws an Error 3270, "Property not found" on the fld.Properties!ColumnWidth line.

While testing, it looks like this code works for all my SQL statements that aren't Summary Queries...it seems whenever I hit a calculated field, this fails. I've tried aliasing other, non-caculated fields like so:
Expand|Select|Wrap|Line Numbers
  1.  strSQL = "SELECT tbl_calendar.SiteName as Test...
...and get no errors, so it's not about the name.

I added a watch to myField to be safe and it's returning "EventCount", which is what the SQL defines. When I open qry_reporting_all, the fields are labeled as expected and the data is correct.

I'm guessing it has to do with Count(). Any ideas?
Jan 10 '13 #1

✓ answered by NeoPa

Firstly, but as an aside, I would suggest you ask yourself why you need a QueryDef object with these different sets of SQL. Bear in mind that such a change to the design of objects in the database make it less flexible as a project. For instance, you won't be able to use it in an MDE or ACCDE project. I'll leave that with you to consider.

As for your problem, I suspect that, for reasons I don't particularly follow, an aggregated field in a QueryDef doesn't have a ColumnWidth property set by default. Seems strange I know, but it appears to be the case nevertheless.

In such a situation I would suggest an error handler that captures this error and handles it by creating the property itself with the required value. I expect that would work. Database Properties has some code that you should be able to use to help with that.

5 5438
NeoPa
32,556 Expert Mod 16PB
Firstly, but as an aside, I would suggest you ask yourself why you need a QueryDef object with these different sets of SQL. Bear in mind that such a change to the design of objects in the database make it less flexible as a project. For instance, you won't be able to use it in an MDE or ACCDE project. I'll leave that with you to consider.

As for your problem, I suspect that, for reasons I don't particularly follow, an aggregated field in a QueryDef doesn't have a ColumnWidth property set by default. Seems strange I know, but it appears to be the case nevertheless.

In such a situation I would suggest an error handler that captures this error and handles it by creating the property itself with the required value. I expect that would work. Database Properties has some code that you should be able to use to help with that.
Jan 10 '13 #2
Thanks, NeoPa; as always, your advice is enlightening. Tell me more about "...you won't be able to use it in an MDE or ACCDE project". I've redefined the SQL behind queries in this way before and made them .accde files.

I imagine there isn't necessarily a "need" for the QueryDef object, but with my limited knowledge, I find something that works and just sort of stick to it. Having only a handful of actual "temp" queries in my object view is visually cleaner to me. When the user says: "Okay, now we want to see this data", I just add a new item to my dropdown, a new SQL statement to the VBA module, and open the same query.
Jan 11 '13 #3
NeoPa
32,556 Expert Mod 16PB
Tetsuo:
I've redefined the SQL behind queries in this way before and made them .accde files.
Interesting. I'm talking more from theory than practice, but I thought the idea of an ACCDE was that the design was unable to be changed, thus guaranteeing users never f^Hmuck up the database. If you find that such an update is possible even in an ACCDE then that's very interesting. It's actually quite a clever approach.

Tetsuo:
I imagine there isn't necessarily a "need" for the QueryDef object
Actually, though you may be correct technically, the QueryDef does give you some nice-to-have control over how the data is displayed. You could even store the field sizes for your list of SQLs.

This brings me on to a suggestion for you :
I've been where you are with arrays of information stored in code. Then I remembered I was working in a database system (Doh!) What I realised then was that it makes much more sense to store the data in a table (or set of tables) and to code around that data, rather than to have the data hard-coded into your modules. I believe this idea can make a very useful and clever setup, even more so (and save you time eventually when setting up new queries in your list).
Jan 11 '13 #4
I think I'm following: rather than coding a new Select case statement / SQL into the module, store it and the dropdown value in a table, set my combobox to the table, and maybe run a DLookup against the associated SQL statement? That'd be accessible from...everywhere.
Jan 15 '13 #5
NeoPa
32,556 Expert Mod 16PB
DLookup() calls are restricted in as much as you cannot use a SQL string value for the Domain parameter. In that sense a QueryDef is preferable, although you could do something very similar with a Recordset object, which would support a SQL string. That said, it seems you have a fairly sound grasp of what I was on about. It's a far more flexible approach than forever redesigning the code.
Jan 15 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: | last post by:
Hi, I am setting the NumericUpDown .Value property and the ValueChanged event is NOT being fired. Does this ONLY get fired when I change it on the UI and not programatically? Thanks
0
by: Neal | last post by:
Hi I am trying to use a 3rd party DLL in my app, (WebService and/or WebApp) I set the references to it, use its public functions and properties OK in Dev mode but when I run it, i get the...
1
by: POnfri | last post by:
Hi, I have a problem in a peace of code were i'm doing a file copy using File.Copy. The Source is local and the target is a remote machine. Example: File.Copy(C:\temp\hi.txt,...
5
by: Yifan | last post by:
Hi Could any one tell me what project property controls the setting of '/RTC1' option? Now I have a project which has this build error "Command line error D2016 : '/RTC1' and '/clr' command-line...
8
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing...
11
by: Alexander Walker | last post by:
Hello I would like to write a method that allows me to pass a reference to an instance of a class, the name of a property of that class and a value to set that property to, the method would then...
2
by: maflatoun | last post by:
Hi everyone, I have the following web user control. I like to set the properties dynamically without using page.databind. <uc1:partnerdownloads id="Partnerdownloads1" PropDomain="<%= Domain...
0
by: cwho.work | last post by:
Hi! We are using apache ibatis with our MySQL 5.0 database (using innodb tables), in our web application running on Tomcat 5. Recently we started getting a number of errors relating to...
0
acoder
by: acoder | last post by:
Problem When setting the FORM object's action property an "Object does not support this property or method" error occurs Browser Internet Explorer 6- Example The Javascript code: var...
3
by: BL3WC | last post by:
Hi, I encountered an error "Object not supporting this properties or method" while trying to set a checkbox value to 'True" in a loop. The VBA code I use is as follow: Set a value to intcount...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
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,...
0
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 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.