Populating dropdown formfield based on another

L

Larry

I need to populate a dropdown formfield, based on what is selected in
another dropdown.

I thought I had it, but something strange is happening now.

I populate both fields (Department and Project) via code. The
PopulateDepartment subroutine is called from both the Document_New and
Document_Open events. Since this form is generated from a template, I
figured it needed to be in the NEW event. But since it can also be modified
after being created, I put it in the OPEN event also.

The data is loaded into the Department field, then I try to set the default
values (which is "..."). I enter the data into an array at the top of the
PopulateDepartment subroutine, the loop on that data to load it into the
dropdown box. The last thing I do is set the .Result value of the formfield
to the first value in the array, which is "...". The exit event for this
dropdown executes the PopulateProject subroutine, which reads this value and
loads the dropdown with the proper data.

BUT, when PopulateProject is executed, it always gets the value I loaded
into the .Result property, regardless of what was selected in the dropdown
field. What am I doing wrong????

Here is how I load the data into the Department dropdown. I assume the
problem is here, since all I am doing in PopulateProjects is getting the
..Result of the formfield.


code:-----------------------------------------------------------------------
-------
intMax = UBound(mstrDepartment)

Set objFormField = Me.FormFields("cboDepartment")
With objFormField
With .DropDown.ListEntries
.Clear
For intCnt = 1 To intMax
.Add Name:=mstrDepartment(intCnt)
Next intCnt
End With
.Result = mstrDepartment(1)
End With
----------------------------------------------------------------------------
--

Now, just b/c I said it and I'm probably wrong, here is some of the code
from the LoadProjects subroutine:

code:-----------------------------------------------------------------------
-------
intDepts = UBound(mstrDepartment)
Set objFormField = Me.FormFields("cboProject")
With objFormField
With .DropDown.ListEntries
.Clear
.Add "..."
For intDept = 1 To intDepts
If strProject(intDept, 0) = strDept Then
For intProj = 1 To 25
If strProject(intDept, intProj) <> "" Then
.Add Name:=strProject(intDept, intProj)
Else
Exit For
End If
Next intProj
End If
Next intDept
End With
.Result = "..."
End With
 
W

Word Heretic

G'day "Larry" <[email protected]>,

is there any code attached to the events on the userform? Why are you
hardsetting .Rresult to begin with?

Steve Hudson
Word Heretic Sydney Australia
Tricky stuff with Word or words

Email: WordHeretic at tpg.com.au


Larry was spinning this yarn:
 

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