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  

Combo box default



 
 
Thread Tools Display Modes
  #1  
Old August 18th, 2009, 11:48 AM posted to microsoft.public.access
Dave
external usenet poster
 
Posts: 105
Default Combo box default

I have an unbound combo box which selects its values from an SQL
statement. I would like this control to default to the first row of
the combo box. BUT, it absolutely refuses to do so. I've tried
[comboname].ItemData(0) in the default property and every other
combination I can think of and nothing! Any ideas??

Dave
  #2  
Old August 18th, 2009, 01:00 PM posted to microsoft.public.access
Jeanette Cunningham
external usenet poster
 
Posts: 2,190
Default Combo box default

Hi Dave,
You can make the combo show the first row of data like this.
Me.[comboname] = Me.[comboname].Itemdata(0)

You would put this code on the form's load event.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

"Dave" wrote in message
...
I have an unbound combo box which selects its values from an SQL
statement. I would like this control to default to the first row of
the combo box. BUT, it absolutely refuses to do so. I've tried
[comboname].ItemData(0) in the default property and every other
combination I can think of and nothing! Any ideas??

Dave



  #3  
Old August 18th, 2009, 01:51 PM posted to microsoft.public.access
Dave
external usenet poster
 
Posts: 105
Default Combo box default

On Aug 18, 8:00*am, "Jeanette Cunningham"
wrote:
Hi Dave,
You can make the combo show the first row of data like this.
Me.[comboname] = Me.[comboname].Itemdata(0)

You would put this code on the form's load event.

Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia

"Dave" wrote in message

...



I have an unbound combo box which selects its values from an SQL
statement. I would like this control to default to the first row of
the combo box. BUT, it absolutely refuses to do so. I've tried
[comboname].ItemData(0) in the default property and every other
combination I can think of and nothing! Any ideas??


Dave- Hide quoted text -


- Show quoted text -


I get a #Name? error

Dave
  #4  
Old August 18th, 2009, 02:59 PM posted to microsoft.public.access
John Spencer
external usenet poster
 
Posts: 7,815
Default Combo box default

By any chance is the bound column value NULL on the first item in the combo?
If so, then
=[comboname].ItemData(0)
will not work. The Null messes things up since Null never matches anything,
including null.

Also, I assume that you are using [ComboName] as a generic example for the
actual name of the combobox and are using the actual name of the combobox in
the expression.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Dave wrote:
I have an unbound combo box which selects its values from an SQL
statement. I would like this control to default to the first row of
the combo box. BUT, it absolutely refuses to do so. I've tried
[comboname].ItemData(0) in the default property and every other
combination I can think of and nothing! Any ideas??

Dave

  #5  
Old August 18th, 2009, 03:07 PM posted to microsoft.public.access
Dave
external usenet poster
 
Posts: 105
Default Combo box default

On Aug 18, 9:59*am, John Spencer wrote:
By any chance is the bound column value NULL on the first item in the combo?
If so, then
* *=[comboname].ItemData(0)
will not work. *The Null messes things up since Null never matches anything,
including null.

Also, I assume that you are using [ComboName] as a generic example for the
actual name of the combobox and are using the actual name of the combobox in
the expression.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County



Dave wrote:
I have an unbound combo box which selects its values from an SQL
statement. I would like this control to default to the first row of
the combo box. BUT, it absolutely refuses to do so. I've tried
[comboname].ItemData(0) in the default property and every other
combination I can think of and nothing! Any ideas??


Dave- Hide quoted text -


- Show quoted text -


Actually, I got it to work if I change the form to design view and
back again. It won't requery no matter where I put a requery request.
Arrgh.

Dave
  #6  
Old August 18th, 2009, 03:42 PM posted to microsoft.public.access
John Spencer
external usenet poster
 
Posts: 7,815
Default Combo box default

Sorry, I am confused at this point.

Are you trying to requery the combobox and then set its value to the first
row? If so, would you care to show us the VBA code you are trying to use and
where you are trying to use it?


I would expect to see something like the following in your code.

Me.NameOfCombobox.Requery
Me.NameOfCombobox = Me.NameOfCombobox.ItemData(0)

'With this temporary line to check to see what is assigned to the combobox
Debug.Print Nz(Me.NameOfCombobox,"NULL VALUE")

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Dave wrote:
On Aug 18, 9:59 am, John Spencer wrote:
By any chance is the bound column value NULL on the first item in the combo?
If so, then
=[comboname].ItemData(0)
will not work. The Null messes things up since Null never matches anything,
including null.

Also, I assume that you are using [ComboName] as a generic example for the
actual name of the combobox and are using the actual name of the combobox in
the expression.

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County



Dave wrote:
I have an unbound combo box which selects its values from an SQL
statement. I would like this control to default to the first row of
the combo box. BUT, it absolutely refuses to do so. I've tried
[comboname].ItemData(0) in the default property and every other
combination I can think of and nothing! Any ideas??
Dave- Hide quoted text -

- Show quoted text -


Actually, I got it to work if I change the form to design view and
back again. It won't requery no matter where I put a requery request.
Arrgh.

Dave

  #7  
Old August 18th, 2009, 04:13 PM posted to microsoft.public.access
Dave
external usenet poster
 
Posts: 105
Default Combo box default

On Aug 18, 10:42*am, John Spencer wrote:
Sorry, I am confused at this point.

Are you trying to requery the combobox and then set its value to the first
row? *If so, would you care to show us the VBA code you are trying to use and
where you are trying to use it?

I would expect to see something like the following in your code.

Me.NameOfCombobox.Requery
Me.NameOfCombobox = Me.NameOfCombobox.ItemData(0)

'With this temporary line to check to see what is assigned to the combobox
Debug.Print Nz(Me.NameOfCombobox,"NULL VALUE")

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County



Dave wrote:
On Aug 18, 9:59 am, John Spencer wrote:
By any chance is the bound column value NULL on the first item in the combo?
If so, then
* *=[comboname].ItemData(0)
will not work. *The Null messes things up since Null never matches anything,
including null.


Also, I assume that you are using [ComboName] as a generic example for the
actual name of the combobox and are using the actual name of the combobox in
the expression.


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County


Dave wrote:
I have an unbound combo box which selects its values from an SQL
statement. I would like this control to default to the first row of
the combo box. BUT, it absolutely refuses to do so. I've tried
[comboname].ItemData(0) in the default property and every other
combination I can think of and nothing! Any ideas??
Dave- Hide quoted text -
- Show quoted text -


Actually, I got it to work if I change the form to design view and
back again. It won't requery no matter where I put a requery request.
Arrgh.


Dave- Hide quoted text -


- Show quoted text -


Yes, John that's exactly what I'm trying to do. The combo box in
question is loaded by a select statement using a text box on the form
called txtRecipPK. On the 'change' event of this text box I have the
following code:

Me.cboResultDate.Requery
Me.cboResultDate = Me.cboResultDate.ItemData(0)

If I go to design view and then back again, it works fine.

Thanks for your help,'

Dave
  #8  
Old August 18th, 2009, 07:41 PM posted to microsoft.public.access
John Spencer
external usenet poster
 
Posts: 7,815
Default Combo box default

Using the change event means that the text property has changed, but the value
of the control has not yet changed.

So a requery should not change anything in the combobox if it is based on the
control.

If you want to change the combobox as things are typed into txtRecipPK then
you will need to change the Combobox.rowsource property.

As a guess you would need something like the following in the change event of
txtRecipPK

Dim StrSQL
StrSQL = "SELECT Field1, Field2 FROM SomeTable WHERE somefield Like "
strSQL = StrSql & Me.txtRecipPK.Text & "*"
strSQL = StrSQL & " ORDER BY Field1"

Me.CboResultDate.ControlSource = StrSQL
Me.cboResultDate = Me.cboResultDate.ItemData(0)


John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County

Dave wrote:
On Aug 18, 10:42 am, John Spencer wrote:
Sorry, I am confused at this point.

Are you trying to requery the combobox and then set its value to the first
row? If so, would you care to show us the VBA code you are trying to use and
where you are trying to use it?

I would expect to see something like the following in your code.

Me.NameOfCombobox.Requery
Me.NameOfCombobox = Me.NameOfCombobox.ItemData(0)

'With this temporary line to check to see what is assigned to the combobox
Debug.Print Nz(Me.NameOfCombobox,"NULL VALUE")

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County



Dave wrote:
On Aug 18, 9:59 am, John Spencer wrote:
By any chance is the bound column value NULL on the first item in the combo?
If so, then
=[comboname].ItemData(0)
will not work. The Null messes things up since Null never matches anything,
including null.
Also, I assume that you are using [ComboName] as a generic example for the
actual name of the combobox and are using the actual name of the combobox in
the expression.
John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
Dave wrote:
I have an unbound combo box which selects its values from an SQL
statement. I would like this control to default to the first row of
the combo box. BUT, it absolutely refuses to do so. I've tried
[comboname].ItemData(0) in the default property and every other
combination I can think of and nothing! Any ideas??
Dave- Hide quoted text -
- Show quoted text -
Actually, I got it to work if I change the form to design view and
back again. It won't requery no matter where I put a requery request.
Arrgh.
Dave- Hide quoted text -

- Show quoted text -


Yes, John that's exactly what I'm trying to do. The combo box in
question is loaded by a select statement using a text box on the form
called txtRecipPK. On the 'change' event of this text box I have the
following code:

Me.cboResultDate.Requery
Me.cboResultDate = Me.cboResultDate.ItemData(0)

If I go to design view and then back again, it works fine.

Thanks for your help,'

Dave

 




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 11:28 AM.


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