Binding Fields to Control Source

N

Nedan Nedzatra

Hia!

How are you doing friends?

I am not able to populate the Text Box in the report!

Sub NewControlsReports()

Dim rpt As Report
Dim ctlLabel As Control, ctlText As Control
Dim intDataX As Integer, intDataY As Integer

Set rpt = CreateReport

rpt.RecordSource = "Contacts"

intDataX = 2000
intDataY = 100

Set ctlText = CreateReportControl(rpt.Name, acTextBox, , "", "", _
intDataX, intDataY)

ctlText.ControlSource = "Notes" '''''I''''' am not sure how to put it here


DoCmd.Restore

End Sub


'Notes' is the field containing data in the table 'Contacts'. This is a
report from a table not from a query. Could someone please correct me!

Thanks.
 
M

Marshall Barton

Nedan said:
I am not able to populate the Text Box in the report!

Sub NewControlsReports()
Dim rpt As Report
Dim ctlLabel As Control, ctlText As Control
Dim intDataX As Integer, intDataY As Integer

Set rpt = CreateReport

rpt.RecordSource = "Contacts"

intDataX = 2000
intDataY = 100

Set ctlText = CreateReportControl(rpt.Name, acTextBox, , "", "", _
intDataX, intDataY)

ctlText.ControlSource = "Notes" '''''I''''' am not sure how to put it here

DoCmd.Restore
End Sub


'Notes' is the field containing data in the table 'Contacts'. This is a
report from a table not from a query. Could someone please correct me!


You are way off base by trying to use CreateReport and
CreateReportControl. Just create the report manually in
design view or, if it does what you want, use an appropriate
report wizard.

FYI, Those two methods should only be used when you want to
create your own design time wizard kind of thing. They
should not be used in a running application.
 
N

Nedan Nedzatra

Hia!

Marshall!

I think what I have been trying is OK!

If my communication was misleading or have I added unnecessary lines of
codes I am sorry.

Thanks!

Sub NewControlsReports()

Dim rpt As Report
Dim intDataX As Integer, intDataY As Integer

Set rpt = CreateReport

rpt.RecordSource = "SELECT [Contacts].Notes FROM [Contacts]"

intDataX = 2000
intDataY = 100

Set ctlText = CreateReportControl(rpt.Name, acTextBox, , "", "", _
intDataX, intDataY)

rpt(ctlText.Name).ControlSource = "Notes"

DoCmd.RunCommand acCmdReportView


End Sub
 
M

Marshall Barton

Nedan said:
I think what I have been trying is OK!

If my communication was misleading or have I added unnecessary lines of
codes I am sorry.

Sub NewControlsReports()

Dim rpt As Report
Dim intDataX As Integer, intDataY As Integer

Set rpt = CreateReport

rpt.RecordSource = "SELECT [Contacts].Notes FROM [Contacts]"

intDataX = 2000
intDataY = 100

Set ctlText = CreateReportControl(rpt.Name, acTextBox, , "", "", _
intDataX, intDataY)

rpt(ctlText.Name).ControlSource = "Notes"

DoCmd.RunCommand acCmdReportView
End Sub

Your question about displaying a value in a text box on a
report should have nothing to do with how the report was
created and your code is extremely unusual. That kind of
code is for experts to use in creating a wizard and your
question implies that you are not an expert. Any other use
of CreateReport and CreateReportControl will cause all kinds
of problems so, unless you are are an expert creating a
design time wizard, what have been trying is NOT OK.

You have not explained the objective so we can not suggest
an appropriate way to achieve the goal. I can state that
you are definitely going about it the wrong way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top