Dynamic fields on forms

J

John Bacon

I need to have a variable number of fields on a form with different names
based upon an array of names
I've succesfully built the form using the code below InitUserFields . UF is
a dynamic array of field names UFV is a matching array of initial values for
each field.

Now I need to retrieve the values that the user enters into the form and
store them back in UFV.

I've tried to use EXECUTE & EVAL as shown in the sub GetUserFields but I
get the error sub or function not defined on ECECUTE or EVAL whichever I use.
I've included references to VB Applications Extensibility 5.3 and Excel 11.0
Object library without any difference.
Does anyone have a better idea of how to achieve this?

Sub InitUserFields(UF, UFV)
Dim X As Integer
Dim NewLabel, NewTextbox
For X = 0 To UBound(UF)
Set NewLabel = Me.Controls.Add("Forms.label.1")
With NewLabel
.Name = UF(X).Name & "Title"
.Caption = UF(X).Name
.Top = 252
.Left = 366 + X * 94
.Width = 90
.Height = 12
.Font.Name = "Tahoma"
End With
Set NewTextbox = Me.Controls.Add("Forms.textbox.1")
With NewTextbox
.Name = UF(X).Name
.Value = UFV(X)
.Top = 264
.Left = 366 + X * 94
.Width = 90
.Height = 15.75
.Font.Name = "Tahoma"
End With
Next
End Sub




Sub GetUserFields(UF, UFV)
Dim X As Integer
For X = 0 To UBound(UF)
Execute (UFV(X) = "Me." & UF(X).Name & ".Value")
Next
End Sub
 
J

John Bacon

Silly me, as soon as I'd posted I saw the answer after spending the previous
4 hours loking for a solution.

Sub GetUserFields(UF, UFV)
Dim X As Integer
For X = 0 To UBound(UF)
UFV(X) = Me.Controls(UF(X).Name).Value
Next
End Sub
 
J

John Bacon

Well in my eyes it's a formin OUTLOOK customised by VBA, but maybe I don't
understand what Outlook custom forms implies, in which case please point me
to the correct forum in case I get another problem in future.
Thanks.
 
S

Sue Mosher [MVP]

Outlook custom forms are the UI/code templates for Outlook message, contact,
and other items. They're quite different from VBA user forms. Questions
about those go in the microsoft.public.outlook.program_vba newsgroup.

And, please, always include your version of Outlook when you post.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
J

John Bacon

Sue,
Thanks for that info. Strange thing is I started in that group and got
directed to this one. Anyway I've got the solution so that's the most
important thing.
 

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