Dynamic fields on forms

Status
Not open for further replies.
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
 
Sorry, but I don't see what this has to do with Outlook custom forms.

Sue Mosher

"John Bacon" <JohnBacon> wrote in message

news:A0264327-29CE-4940-892A-771BD5F3EFE8@microsoft.com...
> 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
 
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

"John Bacon" wrote:


> 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
 
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.

"Sue Mosher [MVP]" wrote:


> Sorry, but I don't see what this has to do with Outlook custom forms.

> > Sue Mosher
> > >

> "John Bacon" <JohnBacon> wrote in message
> news:A0264327-29CE-4940-892A-771BD5F3EFE8@microsoft.com...
> >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


>
 
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

"John Bacon" <JohnBacon> wrote in message

news:271EF4B3-780E-498C-99E2-79B70D76CF10@microsoft.com...
> 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.

> "Sue Mosher [MVP]" wrote:
>
> > Sorry, but I don't see what this has to do with Outlook custom forms.
>

>> "John Bacon" <JohnBacon> wrote in message
> > news:A0264327-29CE-4940-892A-771BD5F3EFE8@microsoft.com...
> > >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

>

>
>>
 
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.

"Sue Mosher [MVP]" wrote:


> 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
> > >

> "John Bacon" <JohnBacon> wrote in message
> news:271EF4B3-780E-498C-99E2-79B70D76CF10@microsoft.com...
> > 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.
> > "Sue Mosher [MVP]" wrote:
> >
> >> Sorry, but I don't see what this has to do with Outlook custom forms.
> >
> >> "John Bacon" <JohnBacon> wrote in message
> >> news:A0264327-29CE-4940-892A-771BD5F3EFE8@microsoft.com...
> >> >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
> >
> >
> >>


>
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
L dynamic and static dates in Outlook contact "notes" ie. body Using Outlook 2
B Emacs Dynamic Abbrev Expansion, Esc-/ Using Outlook 1
Diane Poremsky Using Categories for Dynamic Distribution Lists Using Outlook 0
J Dynamic date range for Outlook Search folders Using Outlook 2
N Creating dynamic forms in outlook?? Using Outlook 2
T Max Recipent or maybe bad dynamic dist list Exchange Server Administration 2
C View doesn't refresh (fields or formatting) Using Outlook 1
M Accessing ALL Outlook contact fields Outlook VBA and Custom Forms 3
Z Import Tasks from Access Using VBA including User Defined Fields Outlook VBA and Custom Forms 0
J Read Outlook Form fields Outlook VBA and Custom Forms 3
G Other users can't see P.2 with custom fields in Form Outlook VBA and Custom Forms 0
S Reference Custom Fields with VBA Outlook VBA and Custom Forms 2
J Outlook 2013 Change color of text in data fields of contacts in Outlook 2013? Using Outlook 10
S User Defined Fields adding new value (2) Using Outlook 0
M vCard does not have user-defined fields from my custom contact form (365) Using Outlook 1
T Outlook 2010 Correct way to map multiple contact fields Using Outlook 4
F Appointment Show All Fields Using Outlook 1
F MAPI, User Defined Fields and perspective after 20 years Outlook VBA and Custom Forms 0
B Outlook Business Contact Manager with SQL to Excel, User Defined Fields in BCM don't sync in SQL. Can I use VBA code to copy 1 field to another? BCM (Business Contact Manager) 0
E To convert imported data to custom fields in Task list Outlook VBA and Custom Forms 1
cimbian street address fields contain 0A0D Outlook VBA and Custom Forms 2
S Custom user fields in received messages Outlook VBA and Custom Forms 1
J Backup .OST - Custom Contact Forms, Defined Fields, Notes Using Outlook 1
P Outlook custom fields "events" Using Outlook 0
J Add Fillable Fields to Existing Template Outlook VBA and Custom Forms 1
B Customize contact record phone fields Using Outlook 2
G Addition of 2 fields based on checkboc true or false Outlook VBA and Custom Forms 2
M Multiple User Defined Fields that can be added, changed, updated using VBA and user form Outlook VBA and Custom Forms 0
R User Defined Fields adding new value Using Outlook 3
S VBA with User Defined fields Outlook VBA and Custom Forms 9
Diane Poremsky Add Attachments and Set Email Fields During a Mail Merge Using Outlook 0
O VBA to extract email (fields and body) to Excel Outlook VBA and Custom Forms 14
H How to export *all* fields from Outlook Using Outlook 2
L Change the displayed fields in calendar view Using Outlook 1
N Export Outlook custom forms fields to excel Outlook VBA and Custom Forms 1
M Recurrence and custom fields Outlook VBA and Custom Forms 0
Diane Poremsky Hiding Global Address Book Fields Using Outlook 0
M Map Outlook user defined fields onto a Sharepoint list ??? Outlook VBA and Custom Forms 1
L Copy email body fields to excel Using Outlook 0
Diane Poremsky Add attachments and set email fields during a mail merge to email Using Outlook 0
H User designed fields not usable in contact folder views Using Outlook 0
L Outlook 2007 Search All Fields in Contacts Using Outlook 1
N How to retrieve user defined fields values to bcm form. Using Outlook 2
N How to disable user defined fields in BCM forms Using Outlook 2
M Adding fields to Task in Outlook Home and Business 2010 Outlook VBA and Custom Forms 7
W Meeting printing background fields Using Outlook 0
N Outlook 2013 vs Outlook.com Email Address fields Using Outlook.com accounts in Outlook 1
S Fields in BCM are overlapping BCM (Business Contact Manager) 2
U Cannot access fields at bottom of Outlook 2013 Contact Rec. Using Outlook 1
C Outlook Custom Contact Form Attach Files in new notes fields Outlook VBA and Custom Forms 3

Similar threads

Back
Top