If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Default value on drop down
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". |
#2
|
|||
|
|||
Default value on drop down
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. |
#3
|
|||
|
|||
Default value on drop down
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) -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Emma" wrote in message ... 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". |
#4
|
|||
|
|||
Default value on drop down
Yes I tried that it doesn't seem to work, I guess it can't be done
"John B. Smotherman" wrote: 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" wrote: 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". |
#5
|
|||
|
|||
Default value on drop down
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. "Douglas J. Steele" wrote: 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) -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Emma" wrote in message ... 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". |
#6
|
|||
|
|||
Default value on drop down
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 -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please) "Emma" wrote in message ... 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. "Douglas J. Steele" wrote: 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) -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Emma" wrote in message ... 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". |
Thread Tools | |
Display Modes | |
|
|