• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 549
  • Last Modified:

Setting .DataFormat param in DataReport

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
jhanf
Asked:
jhanf
  • 4
  • 4
1 Solution
 
Éric MoreauSenior .Net ConsultantCommented:
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
 
Éric MoreauSenior .Net ConsultantCommented:
Anybody home?!?!?!
0
 
jhanfAuthor Commented:
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Éric MoreauSenior .Net ConsultantCommented:
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
 
jhanfAuthor Commented:
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
 
Éric MoreauSenior .Net ConsultantCommented:
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
 
jhanfAuthor Commented:
You are correct.  Sorry I missed the <<Set>> operator.  
0
 
jhanfAuthor Commented:
emoreau - You have been very patient and I thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now