Reading Value From Form Field Dropdown Box

N

Nick Calladine

Hi

I wonder if someone can help me with the syntax on the following problem

I have a table which has the same dropdown form field box each one is called
CIS and is automatically created when added a new row.

I now doing a caculation where i scan through each row of the table and load
each cell in to its own variable so it can be valiadated and then caculated
upon

This is the first time i have used a form fields and struggling finding out
how to read the value of the dropdown box (the options selectable are CIS4 ,
CIS6, VAT, None

so far my code is

For intRows = intFirstUsableRow To .Rows.Count
strDeductionType = .Cell(introw,3). <missing syntax please advise>
Next

Thanks
 
J

Jay Freedman

Hi

I wonder if someone can help me with the syntax on the following problem

I have a table which has the same dropdown form field box each one is called
CIS and is automatically created when added a new row.

I now doing a caculation where i scan through each row of the table and load
each cell in to its own variable so it can be valiadated and then caculated
upon

This is the first time i have used a form fields and struggling finding out
how to read the value of the dropdown box (the options selectable are CIS4 ,
CIS6, VAT, None

so far my code is

For intRows = intFirstUsableRow To .Rows.Count
strDeductionType = .Cell(introw,3). <missing syntax please advise>
Next

Thanks

Hi Nick,

This is a lot more complicated than it ought to be, but that's just
the way it is...

The underlying idea is that a dropdown formfield has two properties,
..ListEntries and .Value, that need to be used together to get the
visible result of the field. You get the .Value, which is the number
of the selected value, and use it as the index into the .ListEntries
collection (basically an array of strings). The string you want is the
..Name property of the selected .ListEntries item. There's an example
in the VBA help topic about .ListEntries.

It's also complicated by the necessary checking to avoid error
messages. You need to be sure there is a formfield in the cell, and
that it's a dropdown rather than a checkbox. Here's the whole nine
yards:

Dim oTbl As Table
Dim intRow As Integer
Dim oDrp As DropDown
Dim strDeductionType As String

Set oTbl = ActiveDocument.Tables(1)
With oTbl
For intRow = 1 To .Rows.Count
If .Cell(intRow, 3).Range.FormFields.Count > 0 Then
Set oDrp = .Cell(intRow, 3).Range.FormFields(1).DropDown
If oDrp.Valid Then
strDeductionType = oDrp.ListEntries(oDrp.Value).Name
MsgBox "Row " & intRow & " = " & strDeductionType
End If
End If
Next
End With
 
N

Nick Calladine

Hi Nick,
This is a lot more complicated than it ought to be, but that's just
the way it is...

Hi Jay

Thanks for the reply.. i understand this most professional way of doing
things but the person for whom it is for has only got word where excel would
be better for this type of thing... and unfortunately since this is about
ver 6 the person is happy with the way he works with the document

The table has a header row and then data in which 2 or 3 parts are set and
then reused every week with a possible change to one figure..

So how would you simplifier it.. more intrested from a different view
point...

but i am sure now with your code.. i will be able to sort the problerm ...

thanks again for your reply
 
J

Jay Freedman

Hi Jay

Thanks for the reply.. i understand this most professional way of doing
things but the person for whom it is for has only got word where excel would
be better for this type of thing... and unfortunately since this is about
ver 6 the person is happy with the way he works with the document

The table has a header row and then data in which 2 or 3 parts are set and
then reused every week with a possible change to one figure..

So how would you simplifier it.. more intrested from a different view
point...

but i am sure now with your code.. i will be able to sort the problerm ...

thanks again for your reply

Hi Nick,

What I was saying was that the stuff I showed is pretty much the
minimum. I suppose you could remove the error-avoidance code and just
use an On Error statement, but I prefer not to do that.

The "simple" way that I'd prefer is a single property that returns the
string currently displayed by the dropdown, but the developers of VBA
didn't include that in the implementation.
 
N

Nick Calladine

Hi Nick,

What I was saying was that the stuff I showed is pretty much the
minimum. I suppose you could remove the error-avoidance code and just
use an On Error statement, but I prefer not to do that.

The "simple" way that I'd prefer is a single property that returns the
string currently displayed by the dropdown, but the developers of VBA
didn't include that in the implementation.

Hi Jay

Yep its all clearer now thanks very much for your advise on the subject it
has help me immenisly.

Thanks again for your time and your positive answers

Nick
 

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