Give name of the Text box from vb code

K

KRISH

Hi! everybody

Below i am giving a sample code to create textbox in
report called Report1tmp. Now I need your help how to give
the name of the textbox while creating it. I dont want the
default names randamly giving by the system like Text1,
Text2,.....


Dim rep As Report
Dim ctrTxtBox As Control

DoCmd.OpenReport "Report1tmp", acViewDesign

Set ctrTxtBox = CreateReportControl("Report1tmp",
acTextBox, acDetail, "Session", "=Session", 100, 100,
1000, 1000)
DoCmd.Restore
DoCmd.RepaintObject
DoCmd.OpenReport "Report1tmp", acViewPreview



Thanks for your help.

Krish
 
G

Graeme Richardson

Hi Krish, since you must have the report in design view to run this
function, you should be able to assignthe name to your new object. Say you
want to call your text box Bob, then

Set ctrTxtBox = CreateReportControl("Report1tmp", acTextBox, acDetail,
"Session", "=Session", 100, 100, 1000, 1000)
ctrTxtBox.Name = "Bob"

Should do the trick. Note: Access has to generate a unique name for the
control in the CreateReportControl function. Doesn't mean you have to keep
it.

Cheers, Graeme.
 
G

Graeme Richardson

Something I just thought of, you do have the report open in design view when
running the CreateReportControl function?
 
K

KRISH

Hi!

Thanks for your response. I have not yet tried with your
solution. It seems it will work fine. I am having another
question. How to delete controls in my report from code.
This will fulfill my problem. Please help.

Looking farward to your reply

Krish
 
G

Graeme Richardson

This works

Public Sub removeReportControl(ByVal vstrReportName As String, ByVal
vstrControlName As String)

Dim rpt As Report
Dim txt As TextBox

DoCmd.OpenReport vstrReportName, acViewDesign
Set rpt = Reports(vstrReportName)

deleteReportControl vstrReportName, vstrControlName

DoCmd.Save acReport, vstrReportName
DoCmd.Close acReport, vstrReportName

End Sub
 

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