0
votes

I am trying to dynamically create controls on a form as needed and I have therefore used the CreateControl Method.

DateControls(i) = CreateControl(Reports!Comments_R, acTextBox, acDetail, , , TopValue, 0, 5400, 1440)

In the following line of code above, when I try to compile the project "CreateControl" is highlighted and a popup box indicates that there is a type mismatch. DateControl is declared as a Control. I have also tried declaring it as a Variant and I still receive the same error. Another time I tried it without using an array and again, still the same error. Any ideas as to what could be wrong?

Thank you.

1
You mention DateControl but your code says DateControls. Do you have Option Explicit at the top of your VBA Module? If not, you should put it there. - Gord Thompson
Yes, I do have Option Explicit and the variable is spelled correctly in my code. - jaromey

1 Answers

0
votes

The type mismatch is on the the first argument to CreateControl. It must be a String. This will get you past the type mismatch error:

    CreateControl(Reports!Comments_R.Name, ...

However, you have two other problems.

  • Since a control is an object, you need to use Set in your assignment statement.

  • It looks like you want to add the control to a Report. If so, use CreateReportControl instead.