Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Dynamically populating textboxes on a form


Hi,

Is there anyway I can auto populate a set of similarly named textboxes
on a user form.

For example, if I have textboxes named txtReporter1 to txtReporter5 I
want to run some code along the lines of:

For i = 1 to 5

FormName.txtReporter & i.Caption = String Value

Next i

The textboxes already exist on the form and are blank but need to
populated differently depending on how a user has accessed the form.

As always, any help is greatly appreciated.

Kind Regards,

Adam


--
Adamaths
------------------------------------------------------------------------
Adamaths's Profile: http://www.excelforum.com/member.php...o&userid=31580
View this thread: http://www.excelforum.com/showthread...hreadid=512806

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Dynamically populating textboxes on a form

For i = 1 to 5

FormName.Controls("txtReporter" & i).Value = String Value

Next i


--

Regards,
Tom Ogilvy


"Adamaths" wrote in
message ...

Hi,

Is there anyway I can auto populate a set of similarly named textboxes
on a user form.

For example, if I have textboxes named txtReporter1 to txtReporter5 I
want to run some code along the lines of:

For i = 1 to 5

FormName.txtReporter & i.Caption = String Value

Next i

The textboxes already exist on the form and are blank but need to
populated differently depending on how a user has accessed the form.

As always, any help is greatly appreciated.

Kind Regards,

Adam


--
Adamaths
------------------------------------------------------------------------
Adamaths's Profile:

http://www.excelforum.com/member.php...o&userid=31580
View this thread: http://www.excelforum.com/showthread...hreadid=512806



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Dynamically populating textboxes on a form


Hi,

Thanks for your help on this. I'm still having what is hopefully a
minor problem. The reason for this, I believe is that I'm populating
the form dynamically in a sub routine to which I am passing the name of
the form as a string since the form to populate can change each time.

At the moment, my code reads:

Sub PopulateHeadingsByName(FormName As String)

Dim oUserForm As Object 'Will hold the name of the form to
populate

'Set the object to be the user form we wish to populate
Set oUserForm = UserForms.Add(FormName)

'Cycle through each part of the form - NumberOfComponents is a
public variable
For i = 1 to NumberofComponents

'Populate the txtPeriod textbox
oUserForm.Controls("txtHeadingPart" & i).Value =
RequiredValue

Next i

The code compiles and runs without any error/debug messages. I know
that the required value is not null and that the control exists on the
form, yet it is not populated. I'm guessing this is due to the way I
am definining the form as an object?

Any help to get this working would be greatly apprecaiated.

Regards,

Adam

End Sub


--
Adamaths
------------------------------------------------------------------------
Adamaths's Profile: http://www.excelforum.com/member.php...o&userid=31580
View this thread: http://www.excelforum.com/showthread...hreadid=512806

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Dynamically populating textboxes on a form

I suspect it is populated. As a debug approach, show the form after you
populate it.


Sub PopulateHeadingsByName(FormName As String)

Dim oUserForm As Object 'Will hold the name of the form to
populate

'Set the object to be the user form we wish to populate
Set oUserForm = UserForms.Add(FormName)

'Cycle through each part of the form - NumberOfComponents is a
public variable
For i = 1 to NumberofComponents

'Populate the txtPeriod textbox
oUserForm.Controls("txtHeadingPart" & i).Value = RequiredValue

Next i
oUserForm.Show

End Sub


I suspect that you are probably creating a new instance of the form and not
the instance you intend to work with.

I would pass in a useform object rather than a text string. Or if the
userform already exits (it is already loaded), then retrieve it from the
userforms collection rather than adding it.


See method 3 in
http://support.microsoft.com/kb/207714/en-us

--
Regards,
Tom Ogilvy


"Adamaths" wrote in
message ...

Hi,

Thanks for your help on this. I'm still having what is hopefully a
minor problem. The reason for this, I believe is that I'm populating
the form dynamically in a sub routine to which I am passing the name of
the form as a string since the form to populate can change each time.

At the moment, my code reads:

Sub PopulateHeadingsByName(FormName As String)

Dim oUserForm As Object 'Will hold the name of the form to
populate

'Set the object to be the user form we wish to populate
Set oUserForm = UserForms.Add(FormName)

'Cycle through each part of the form - NumberOfComponents is a
public variable
For i = 1 to NumberofComponents

'Populate the txtPeriod textbox
oUserForm.Controls("txtHeadingPart" & i).Value =
RequiredValue

Next i

The code compiles and runs without any error/debug messages. I know
that the required value is not null and that the control exists on the
form, yet it is not populated. I'm guessing this is due to the way I
am definining the form as an object?

Any help to get this working would be greatly apprecaiated.

Regards,

Adam

End Sub


--
Adamaths
------------------------------------------------------------------------
Adamaths's Profile:

http://www.excelforum.com/member.php...o&userid=31580
View this thread: http://www.excelforum.com/showthread...hreadid=512806



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Dynamically populating textboxes on a form


Many thanks for your help - it is now working a treat.

In the end I added this into the main code of the previous forms
button:

For i = 0 To UserForms.Count - 1
If UserForms.Item(i).Name = FormName Then
PopulateHeadingsByName (i)
End If
Next i

In the Open Workbook event I have loaded all forms then hidden all but
one, so this finds the index of the form I want to show and passes that
to my other subroutine.

By then using

UserForms.Item(Index).Controls(textboxname).value = reuiqred value

they all get popoulated and shown.

Works brilliantly.

Thanks for all your help.

Regards,

Adam


--
Adamaths
------------------------------------------------------------------------
Adamaths's Profile: http://www.excelforum.com/member.php...o&userid=31580
View this thread: http://www.excelforum.com/showthread...hreadid=512806



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign click functionality to dynamically created textboxes? Ouka[_17_] Excel Programming 3 August 25th 05 03:15 AM
TextBoxes on a Form Neil Excel Programming 4 June 4th 04 01:25 PM
Problem with populating textboxes in relation to drop down list Ben Allen Excel Programming 0 April 26th 04 09:40 PM
Program a combobox/dropdownlist to create textboxes dynamically ed Excel Programming 0 October 30th 03 09:02 PM
Dynamically populating and formatting cells with Essbase members BrianB Excel Programming 0 July 24th 03 10:08 AM


All times are GMT +1. The time now is 11:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"