Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Setting .DataFormat param in DataReport

Posted on 2000-02-24
8
Medium Priority
?
542 Views
Last Modified: 2013-12-26
I am trying to set the DataFormat property for a textbox in the detail section of a DataReport and I get a runtime error 438, "Object doesn't support this property or method."

The code is as follows:

dr.Sections(3).Controls(x).DataFormat = "#,###.00" (or similar)

I am using a SQL 7.0 database bound to the DataReport through a DataEnvironment object.  I have also tried using an unbound data source with the same result.
0
Comment
Question by:jhanf
  • 4
  • 4
8 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2560862
What is the control you want to format? You can display its name to ensure you have the right one (msgbox dr.Sections(3).Controls(x).name). The DataFormat property can only be used if the field is bound!!!
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2568652
Anybody home?!?!?!
0
 

Author Comment

by:jhanf
ID: 2568862
The control is a textbox in the detail section.  I verified the name of the control, and that it is indeed bound.  Still, the same error message appears.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2568959
You can't set it this way. You need to use the Format object.

First, add a reference to the «Microsoft Data Formatting object library».

Then add this code to your application:
Dim fmtX As StdDataFormat
Set fmtX = New StdDataFormat
fmtX.Type = fmtCustom
fmtX.Format = "#,###.00"
Set dr.Sections(3).Controls(x).DataFormat = fmtX
0
 

Author Comment

by:jhanf
ID: 2569690
Okay, that is useful information; but the error message is generated when referencing the .DataFormat property.  VB doesn't seem to care what is on the right side of the equals sign at this point.
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 400 total points
ID: 2569994
Since fmtX is an object, you have to use the «SET» operator like I have written in my last example.

I just build a very small demo and here is the code (that works well):

Private Sub Command1_Click()
Dim fmtX As StdDataFormat

    Set fmtX = New StdDataFormat
    fmtX.Type = fmtCustom
    fmtX.Format = "#,###.00"
    Set DataReport1.Sections(2).Controls(4).DataFormat = fmtX
    DataReport1.Show
End Sub
0
 

Author Comment

by:jhanf
ID: 2570110
You are correct.  Sorry I missed the <<Set>> operator.  
0
 

Author Comment

by:jhanf
ID: 2570113
emoreau - You have been very patient and I thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

916 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