Default value on drop down

E

Emma

I'm using 2007 and have recently upgraded one combobox to allow for multiple
selections I was wondering how I set the default value of the drop down,
here's what I have:
Me.Housing_Risk.Value = "At Risk of Homelessness"

But when I run it; it says, "can not perform this operation".
 
J

John B. Smotherman

Have you tried setting the default value for the control in the form's design?

Open the form in design view. If the property sheet is not visible,
right-click in an empty area of the form and choose "Properties" from the
popup menu. Click the control and find "Default Value" on the Data tab. Enter
[="At Risk of Homelessness"] (without the square brackets).

HTH

B.
 
D

Douglas J. Steele

Combo boxes don't allow for multiple selections: only list boxes do.

If you meant list box, you need to use the Selected property:

Dim lngLoop As Long

For lngLoop = 0 To (Me!Housing_Risk.ListCount - 1)
If Me!Housing_Risk.ItemData(lngLoop) = "At Risk of Homelessness" Then
Me!Housing_Risk.Selected(lngLoop) = True
Exit For
End If
Next lngLoop

That assumes that the field containing the text is the bound field. If some
other field is bound, you'll need to use the Column collection. For
instance, if the second column is the one that contains the text, you'd use

Dim lngLoop As Long

For lngLoop = 0 To (Me!Housing_Risk.ListCount - 1)
If Me!Housing_Risk.Column(1, lngLoop) = "At Risk of Homelessness" Then
Me!Housing_Risk.Selected(lngLoop) = True
Exit For
End If
Next lngLoop

(Note that the Column collection starts numbering at 0)
 
E

Emma

Yes I tried that it doesn't seem to work, I guess it can't be done

John B. Smotherman said:
Have you tried setting the default value for the control in the form's design?

Open the form in design view. If the property sheet is not visible,
right-click in an empty area of the form and choose "Properties" from the
popup menu. Click the control and find "Default Value" on the Data tab. Enter
[="At Risk of Homelessness"] (without the square brackets).

HTH

B.

Emma said:
I'm using 2007 and have recently upgraded one combobox to allow for multiple
selections I was wondering how I set the default value of the drop down,
here's what I have:
Me.Housing_Risk.Value = "At Risk of Homelessness"

But when I run it; it says, "can not perform this operation".
 
E

Emma

Hi Douglas,

It seems to be doing something, the cursor goes to the Housing staus field
but the value isn't "At Risk of Homelessness". I tried it both ways you gave
me.
 
D

Douglas J. Steele

What happens if you (temporarily) change it to

Dim booFound As Boolean
Dim lngLoop As Long

booFound = False
For lngLoop = 0 To (Me!Housing_Risk.ListCount - 1)
If Me!Housing_Risk.ItemData(lngLoop) = "At Risk of Homelessness" Then
Me!Housing_Risk.Selected(lngLoop) = True
MsgBox "At Risk of Homelessness was found in row " & (lngLoop + 1)
booFound = True
Exit For
End If
Next lngLoop

If booFound = False Then
MsgBox "At Risk of Homelessness wasn't found in any row"
End If
 

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

Similar Threads


Top