Default value on drop down

  • Thread starter Thread starter Emma
  • Start date Start date
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".
 
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.
 
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)
 
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".
 
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.
 
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
 
Back
Top