Drop Down Form Field Problems

B

Blech

Hi - I have a drop-down form field in a document with a macro attached
to the entry event for the control. The macro queries an Access
database via ADO and then populates the control's entries. The
problem I'm having is when a user clicks on the control to select an
entry; the entry is selected for a moment and then gets reset to a
blank. When the user selects the control again, the entry remains
selected. This behavior occurs anytime the user moves from another
form field on the document to the drop down control. I have no idea
what is causing this behavior. Any suggestions are appreciated!

Thanks,

Geoff
 
D

DA

Hi Geoff

Sounds like you're not setting the text property of the
control properly. Without seeing some code it's hard to
tell what you're actually doing. When you say entry
event, do you mean "_Change()"?

Also, "..the entry is selected for a moment and then gets
reset to a blank", does this mean the field resets itself
while the user is on it?

I'd like to help out, but I'm afraid we may need a bit
more detail.

Dennis
 
B

Blech

DA said:
Hi Geoff

Sounds like you're not setting the text property of the
control properly. Without seeing some code it's hard to
tell what you're actually doing. When you say entry
event, do you mean "_Change()"?

Not sure what you mean by "text property"...I don't see a text
property for the drop-down form field control. In the properties for
the control, I have a macro - getCategories - defined for the entry
event of the control. Here's the code for getCategories:

Public Sub getCategories()
' This sub is called by the entry event of the Category drop down
form field.
' The purpose is to retrieve a list of valid categories and
populate the drop down entries

Dim vConnection As New ADODB.Connection
Dim rsCategory As New ADODB.Recordset

vConnection.ConnectionString = "data source=WIP Repair
Status.mdb;" & _
"Provider=Microsoft.Jet.OLEDB.4.0;"
vConnection.Open

rsCategory.Open "select CategoryDescription from Categories where
CategoryID >= 0", vConnection, adOpenKeyset, adLockOptimistic
rsCategory.MoveFirst

'clear the current entries before adding the current categories
ActiveDocument.FormFields("bkCmbCategory").DropDown.ListEntries.Clear

Do Until rsCategory.EOF
strCategory = rsCategory("CategoryDescription")
ActiveDocument.FormFields("bkCmbCategory").DropDown.ListEntries.Add
strCategory
rsCategory.MoveNext
Loop
rsCategory.Close
Set rsCategory = Nothing

Set vConnection = Nothing
End Sub
Also, "..the entry is selected for a moment and then gets
reset to a blank", does this mean the field resets itself
while the user is on it?

No - the field is reset after the user has selected an entry and has
left the field.
I'd like to help out, but I'm afraid we may need a bit
more detail.

Dennis

Thanks for your help.

Geoff
 
D

DA

First of all, sorry for confusing you with the text
property, as I had incorrectly assumed you were using a
VBA form (as in a combo box drop down).

There's nothing really wrong with your code.
Unless you have some other macro action OnExit, the
selected value should stay.

Your code will however clear the drop-down when you move
focus back to the field at any stage. I'm not sure if
this is the problem you're trying to overcome. If it is,
then I'd suggest a check on the value to tell you if the
user selected something.

Wrap your entire routine around this check:

---------
If ActiveDocument.FormFields
("bkCmbCategory").DropDown.Value = 0 Then

<rest of your sub>

End If
---------

This way you will not open the database, clear the field
and repopluate it unecessarily.

Hope that helps..

Dennis
 

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