A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Default value on drop down



 
 
Thread Tools Display Modes
  #1  
Old May 11th, 2009, 05:01 PM posted to microsoft.public.access
Emma
external usenet poster
 
Posts: 493
Default 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  
Old May 11th, 2009, 05:37 PM posted to microsoft.public.access
John B. Smotherman
external usenet poster
 
Posts: 55
Default 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  
Old May 11th, 2009, 06:25 PM posted to microsoft.public.access
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default 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  
Old May 11th, 2009, 06:51 PM posted to microsoft.public.access
Emma
external usenet poster
 
Posts: 493
Default 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  
Old May 11th, 2009, 07:14 PM posted to microsoft.public.access
Emma
external usenet poster
 
Posts: 493
Default 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  
Old May 11th, 2009, 09:54 PM posted to microsoft.public.access
Douglas J. Steele[_3_]
external usenet poster
 
Posts: 3,143
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:33 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.