First entry in combo

H

hughess7

Hi all

I am using the code:

Me!CountryCode = Me!CountryCode.ItemData(0)

to populate the combo box with the first row data when a form is entered
(open event won't work so I am using the OnCurrent event).

BUT, the first entry is additional data added to the combo via sql:

SELECT CountryCode, Country FROM [qry Countries] UNION Select NULL as
AllChoice, "(Select Country)" as Bogus From [qry Countries] ORDER BY Country;

When I open the form the combo box is null, (Select Country) is at the top
of the list if I press the down arrow but I want this displaying in the field
when I open the form.

Is this possible?

Thanks in advance for any help.
Sue
 
B

BruceM

I am having some trouble understanding your question. Perhaps I am not
alone in this.

From what I can tell you are trying to populate a field with the first item
in the combo box Row Source. Since you are doing this in the form's Current
event you are setting the field's value to that first item in every record.
The user could change it, but the next time you arrive at that record it
will be changed back.

I doubt that was your intention. More likely you mean the combo box Default
Value should be (Select Country). Default Value applies only to new
records. If the bound column is the first one, the default value would be
that field. I don't know if Null would work as the default value, but you
could change the Row Source to something like:

SELECT CountryCode, Country FROM [qry Countries] UNION Select "PickOne" AS
AllChoice, "(Select Country)" AS Bogus From [qry Countries] ORDER BY
Country;

I recognize the code. I'm not sure the reason for the aliases. I have had
success with somethng like this, as I recall:

SELECT CountryCode, Country FROM [qry Countries] UNION Select "PickOne",
"(Select Country)" FROM [qry Countries] ORDER BY Country;

In any case, you should be able to set the Default Value for the combo box
to the "PickOne" or "(Select Country)", or to ItemData(0)
 
B

BruceM

Just to clarify a little, the default value would be either the bound column
value or ItemData(0). If the bound column is CountryCode, "PickOne" is the
default value you would use if you are going the hard-coding route.

BruceM said:
I am having some trouble understanding your question. Perhaps I am not
alone in this.

From what I can tell you are trying to populate a field with the first
item in the combo box Row Source. Since you are doing this in the form's
Current event you are setting the field's value to that first item in
every record. The user could change it, but the next time you arrive at
that record it will be changed back.

I doubt that was your intention. More likely you mean the combo box
Default Value should be (Select Country). Default Value applies only to
new records. If the bound column is the first one, the default value
would be that field. I don't know if Null would work as the default
value, but you could change the Row Source to something like:

SELECT CountryCode, Country FROM [qry Countries] UNION Select "PickOne" AS
AllChoice, "(Select Country)" AS Bogus From [qry Countries] ORDER BY
Country;

I recognize the code. I'm not sure the reason for the aliases. I have
had success with somethng like this, as I recall:

SELECT CountryCode, Country FROM [qry Countries] UNION Select "PickOne",
"(Select Country)" FROM [qry Countries] ORDER BY Country;

In any case, you should be able to set the Default Value for the combo box
to the "PickOne" or "(Select Country)", or to ItemData(0)

hughess7 said:
Hi all

I am using the code:

Me!CountryCode = Me!CountryCode.ItemData(0)

to populate the combo box with the first row data when a form is entered
(open event won't work so I am using the OnCurrent event).

BUT, the first entry is additional data added to the combo via sql:

SELECT CountryCode, Country FROM [qry Countries] UNION Select NULL as
AllChoice, "(Select Country)" as Bogus From [qry Countries] ORDER BY
Country;

When I open the form the combo box is null, (Select Country) is at the
top
of the list if I press the down arrow but I want this displaying in the
field
when I open the form.

Is this possible?

Thanks in advance for any help.
Sue
 
K

kate

BruceM said:
Just to clarify a little, the default value would be either the bound
column value or ItemData(0). If the bound column is CountryCode,
"PickOne" is the default value you would use if you are going the
hard-coding route.

BruceM said:
I am having some trouble understanding your question. Perhaps I am not
alone in this.

From what I can tell you are trying to populate a field with the first
item in the combo box Row Source. Since you are doing this in the form's
Current event you are setting the field's value to that first item in
every record. The user could change it, but the next time you arrive at
that record it will be changed back.

I doubt that was your intention. More likely you mean the combo box
Default Value should be (Select Country). Default Value applies only to
new records. If the bound column is the first one, the default value
would be that field. I don't know if Null would work as the default
value, but you could change the Row Source to something like:

SELECT CountryCode, Country FROM [qry Countries] UNION Select "PickOne"
AS
AllChoice, "(Select Country)" AS Bogus From [qry Countries] ORDER BY
Country;

I recognize the code. I'm not sure the reason for the aliases. I have
had success with somethng like this, as I recall:

SELECT CountryCode, Country FROM [qry Countries] UNION Select "PickOne",
"(Select Country)" FROM [qry Countries] ORDER BY Country;

In any case, you should be able to set the Default Value for the combo
box to the "PickOne" or "(Select Country)", or to ItemData(0)

hughess7 said:
Hi all

I am using the code:

Me!CountryCode = Me!CountryCode.ItemData(0)

to populate the combo box with the first row data when a form is entered
(open event won't work so I am using the OnCurrent event).

BUT, the first entry is additional data added to the combo via sql:

SELECT CountryCode, Country FROM [qry Countries] UNION Select NULL as
AllChoice, "(Select Country)" as Bogus From [qry Countries] ORDER BY
Country;

When I open the form the combo box is null, (Select Country) is at the
top
of the list if I press the down arrow but I want this displaying in the
field
when I open the form.

Is this possible?

Thanks in advance for any help.
Sue
 
H

hughess7

Thanks for the reply. Sorry I didn't make it very clear! The form only ever
has one record displayed, each time it is opened it will be a new record. It
is a simple data request form for the user to choose a country and dealer to
produce claim data for. It has some subforms on it though too - one too
display dealer history (once selections have been made) and one to show the
claim data summary row once it has been run from a 'Create Claim data' button.

That is all working so you don't need to worry about that... it is just
background info to try and explain what I am doing.

What I would like when I open the form is for (Select Country) and (Select
Dealer) to be showing in the combo boxes on the form. I found this code,
mentioned previously, on these forums and it kind of does what I want. I am
using it because Limit to List is set to Yes also which is what I want. What
happens though is instead of displaying (Select Country) is it displays a
null value. The dealer combo is blank until a country is chosen, I will
update this combo afer a country has been selected.

I will try what you have suggested but I have a feeling they won't work as I
think I've already tried putting similar when trying to get this to work
myself. I too didn't understand the need for alias, but like I said I copied
this code off a different posting. Without the alias it wasn't working, I
also tried removing Null and putting "SelectCountry" but that errored with a
parameter prompt not recognising it as a field.

I will have another go now and post back thanks...


BruceM said:
Just to clarify a little, the default value would be either the bound column
value or ItemData(0). If the bound column is CountryCode, "PickOne" is the
default value you would use if you are going the hard-coding route.

BruceM said:
I am having some trouble understanding your question. Perhaps I am not
alone in this.

From what I can tell you are trying to populate a field with the first
item in the combo box Row Source. Since you are doing this in the form's
Current event you are setting the field's value to that first item in
every record. The user could change it, but the next time you arrive at
that record it will be changed back.

I doubt that was your intention. More likely you mean the combo box
Default Value should be (Select Country). Default Value applies only to
new records. If the bound column is the first one, the default value
would be that field. I don't know if Null would work as the default
value, but you could change the Row Source to something like:

SELECT CountryCode, Country FROM [qry Countries] UNION Select "PickOne" AS
AllChoice, "(Select Country)" AS Bogus From [qry Countries] ORDER BY
Country;

I recognize the code. I'm not sure the reason for the aliases. I have
had success with somethng like this, as I recall:

SELECT CountryCode, Country FROM [qry Countries] UNION Select "PickOne",
"(Select Country)" FROM [qry Countries] ORDER BY Country;

In any case, you should be able to set the Default Value for the combo box
to the "PickOne" or "(Select Country)", or to ItemData(0)

hughess7 said:
Hi all

I am using the code:

Me!CountryCode = Me!CountryCode.ItemData(0)

to populate the combo box with the first row data when a form is entered
(open event won't work so I am using the OnCurrent event).

BUT, the first entry is additional data added to the combo via sql:

SELECT CountryCode, Country FROM [qry Countries] UNION Select NULL as
AllChoice, "(Select Country)" as Bogus From [qry Countries] ORDER BY
Country;

When I open the form the combo box is null, (Select Country) is at the
top
of the list if I press the down arrow but I want this displaying in the
field
when I open the form.

Is this possible?

Thanks in advance for any help.
Sue
 
H

hughess7

Just to clarify - there is only ever one record in the table (RecordSource of
form) and it is overwritten each time more claim data is created, it is a
temp table of sorts therefore default value won't work as it is never a 'new'
record, always an amended one....

hughess7 said:
Thanks for the reply. Sorry I didn't make it very clear! The form only ever
has one record displayed, each time it is opened it will be a new record. It
is a simple data request form for the user to choose a country and dealer to
produce claim data for. It has some subforms on it though too - one too
display dealer history (once selections have been made) and one to show the
claim data summary row once it has been run from a 'Create Claim data' button.

That is all working so you don't need to worry about that... it is just
background info to try and explain what I am doing.

What I would like when I open the form is for (Select Country) and (Select
Dealer) to be showing in the combo boxes on the form. I found this code,
mentioned previously, on these forums and it kind of does what I want. I am
using it because Limit to List is set to Yes also which is what I want. What
happens though is instead of displaying (Select Country) is it displays a
null value. The dealer combo is blank until a country is chosen, I will
update this combo afer a country has been selected.

I will try what you have suggested but I have a feeling they won't work as I
think I've already tried putting similar when trying to get this to work
myself. I too didn't understand the need for alias, but like I said I copied
this code off a different posting. Without the alias it wasn't working, I
also tried removing Null and putting "SelectCountry" but that errored with a
parameter prompt not recognising it as a field.

I will have another go now and post back thanks...


BruceM said:
Just to clarify a little, the default value would be either the bound column
value or ItemData(0). If the bound column is CountryCode, "PickOne" is the
default value you would use if you are going the hard-coding route.

BruceM said:
I am having some trouble understanding your question. Perhaps I am not
alone in this.

From what I can tell you are trying to populate a field with the first
item in the combo box Row Source. Since you are doing this in the form's
Current event you are setting the field's value to that first item in
every record. The user could change it, but the next time you arrive at
that record it will be changed back.

I doubt that was your intention. More likely you mean the combo box
Default Value should be (Select Country). Default Value applies only to
new records. If the bound column is the first one, the default value
would be that field. I don't know if Null would work as the default
value, but you could change the Row Source to something like:

SELECT CountryCode, Country FROM [qry Countries] UNION Select "PickOne" AS
AllChoice, "(Select Country)" AS Bogus From [qry Countries] ORDER BY
Country;

I recognize the code. I'm not sure the reason for the aliases. I have
had success with somethng like this, as I recall:

SELECT CountryCode, Country FROM [qry Countries] UNION Select "PickOne",
"(Select Country)" FROM [qry Countries] ORDER BY Country;

In any case, you should be able to set the Default Value for the combo box
to the "PickOne" or "(Select Country)", or to ItemData(0)

Hi all

I am using the code:

Me!CountryCode = Me!CountryCode.ItemData(0)

to populate the combo box with the first row data when a form is entered
(open event won't work so I am using the OnCurrent event).

BUT, the first entry is additional data added to the combo via sql:

SELECT CountryCode, Country FROM [qry Countries] UNION Select NULL as
AllChoice, "(Select Country)" as Bogus From [qry Countries] ORDER BY
Country;

When I open the form the combo box is null, (Select Country) is at the
top
of the list if I press the down arrow but I want this displaying in the
field
when I open the form.

Is this possible?

Thanks in advance for any help.
Sue
 
H

hughess7

The simplfied version works thanks :). I realised why I was getting an error
previously - country code is only 2 chars so I had to use "SC" instead and it
worked.

hughess7 said:
Just to clarify - there is only ever one record in the table (RecordSource of
form) and it is overwritten each time more claim data is created, it is a
temp table of sorts therefore default value won't work as it is never a 'new'
record, always an amended one....

hughess7 said:
Thanks for the reply. Sorry I didn't make it very clear! The form only ever
has one record displayed, each time it is opened it will be a new record. It
is a simple data request form for the user to choose a country and dealer to
produce claim data for. It has some subforms on it though too - one too
display dealer history (once selections have been made) and one to show the
claim data summary row once it has been run from a 'Create Claim data' button.

That is all working so you don't need to worry about that... it is just
background info to try and explain what I am doing.

What I would like when I open the form is for (Select Country) and (Select
Dealer) to be showing in the combo boxes on the form. I found this code,
mentioned previously, on these forums and it kind of does what I want. I am
using it because Limit to List is set to Yes also which is what I want. What
happens though is instead of displaying (Select Country) is it displays a
null value. The dealer combo is blank until a country is chosen, I will
update this combo afer a country has been selected.

I will try what you have suggested but I have a feeling they won't work as I
think I've already tried putting similar when trying to get this to work
myself. I too didn't understand the need for alias, but like I said I copied
this code off a different posting. Without the alias it wasn't working, I
also tried removing Null and putting "SelectCountry" but that errored with a
parameter prompt not recognising it as a field.

I will have another go now and post back thanks...


BruceM said:
Just to clarify a little, the default value would be either the bound column
value or ItemData(0). If the bound column is CountryCode, "PickOne" is the
default value you would use if you are going the hard-coding route.

"BruceM" <bamoob_at_yawhodotcalm.not> wrote in message
I am having some trouble understanding your question. Perhaps I am not
alone in this.

From what I can tell you are trying to populate a field with the first
item in the combo box Row Source. Since you are doing this in the form's
Current event you are setting the field's value to that first item in
every record. The user could change it, but the next time you arrive at
that record it will be changed back.

I doubt that was your intention. More likely you mean the combo box
Default Value should be (Select Country). Default Value applies only to
new records. If the bound column is the first one, the default value
would be that field. I don't know if Null would work as the default
value, but you could change the Row Source to something like:

SELECT CountryCode, Country FROM [qry Countries] UNION Select "PickOne" AS
AllChoice, "(Select Country)" AS Bogus From [qry Countries] ORDER BY
Country;

I recognize the code. I'm not sure the reason for the aliases. I have
had success with somethng like this, as I recall:

SELECT CountryCode, Country FROM [qry Countries] UNION Select "PickOne",
"(Select Country)" FROM [qry Countries] ORDER BY Country;

In any case, you should be able to set the Default Value for the combo box
to the "PickOne" or "(Select Country)", or to ItemData(0)

Hi all

I am using the code:

Me!CountryCode = Me!CountryCode.ItemData(0)

to populate the combo box with the first row data when a form is entered
(open event won't work so I am using the OnCurrent event).

BUT, the first entry is additional data added to the combo via sql:

SELECT CountryCode, Country FROM [qry Countries] UNION Select NULL as
AllChoice, "(Select Country)" as Bogus From [qry Countries] ORDER BY
Country;

When I open the form the combo box is null, (Select Country) is at the
top
of the list if I press the down arrow but I want this displaying in the
field
when I open the form.

Is this possible?

Thanks in advance for any help.
Sue
 

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