code for autopopulate...

  • Thread starter Thread starter Kels
  • Start date Start date
K

Kels

Hi

I have a table that containts list of events and prices etc.

I have a form based on this table. However, what i want to do is select the
name of the event from a combo box and then the rest of the fields to
automatically fill when that even is selected, to display the price and
location for that event.

I have entered the following code in the Control source box
=[Event].[Column](0) and then the following code in the Row source box SELECT
EventName, Event Price FROM Events;

I've set the column widths to 1cm

However I keep getting an error message of Syntax Error (missing operator)
in query Expression "Event Price"

Can you tell me where I'm going wrong and how to get this form working?

Thanks
 
If Event Price has a space as you have shown it needs to be in square
brackets.
SELECT [EventName], [Event Price] FROM Events ORDER BY [EventName]

I added the ORDER BY as a suggestion. Also, I tend to use square brackets
around all field names just to make it easier to read.
 
Because you have a space in your field name, you need to enclise it in square
brackets to denote a field
SELECT EventName, [Event Price] FROM Events;
 
Thanks, that seems to have worked! but can you tell me what I need to put in
the control source field? I have the following =[Event].[Column](0) but it's
coming up as an error "Invalid control source" Therefore the drop down box is
blank

thanks!

BruceM said:
If Event Price has a space as you have shown it needs to be in square
brackets.
SELECT [EventName], [Event Price] FROM Events ORDER BY [EventName]

I added the ORDER BY as a suggestion. Also, I tend to use square brackets
around all field names just to make it easier to read.

Kels said:
Hi

I have a table that containts list of events and prices etc.

I have a form based on this table. However, what i want to do is select
the
name of the event from a combo box and then the rest of the fields to
automatically fill when that even is selected, to display the price and
location for that event.

I have entered the following code in the Control source box
=[Event].[Column](0) and then the following code in the Row source box
SELECT
EventName, Event Price FROM Events;

I've set the column widths to 1cm

However I keep getting an error message of Syntax Error (missing operator)
in query Expression "Event Price"

Can you tell me where I'm going wrong and how to get this form working?

Thanks
 
Sorry! I have sorted out the error but the drop down box is coming up blank...

BruceM said:
If Event Price has a space as you have shown it needs to be in square
brackets.
SELECT [EventName], [Event Price] FROM Events ORDER BY [EventName]

I added the ORDER BY as a suggestion. Also, I tend to use square brackets
around all field names just to make it easier to read.

Kels said:
Hi

I have a table that containts list of events and prices etc.

I have a form based on this table. However, what i want to do is select
the
name of the event from a combo box and then the rest of the fields to
automatically fill when that even is selected, to display the price and
location for that event.

I have entered the following code in the Control source box
=[Event].[Column](0) and then the following code in the Row source box
SELECT
EventName, Event Price FROM Events;

I've set the column widths to 1cm

However I keep getting an error message of Syntax Error (missing operator)
in query Expression "Event Price"

Can you tell me where I'm going wrong and how to get this form working?

Thanks
 
Me again!!!

Sorry, I've fixed these problems, and when I click the box the list of
events appear but I can't select any, I get a message saying "Control can't
be edited it is bound by
"Kels" wrote: =[Event].[Column](0)

Any ideas how I can fix this?

thanks again ;o)
 
If Event is the name of the combo box, this would be the control source of
an unbound text box in which the first column (Column(0) of the combo box
Row Source is to appear:
=[Event].[Column](0)

It is *not* the combo box Control Source. That would be the field in which
you want the selection to be stored.

After you make a selection from a bound combo box (a bound combo box has a
Control Source from the form's Record Source) it will store the data that is
in the bound column, no matter what it displays.

Kels said:
Me again!!!

Sorry, I've fixed these problems, and when I click the box the list of
events appear but I can't select any, I get a message saying "Control
can't
be edited it is bound by
"Kels" wrote: =[Event].[Column](0)

Any ideas how I can fix this?

thanks again ;o)
Hi

I have a table that containts list of events and prices etc.

I have a form based on this table. However, what i want to do is select
the
name of the event from a combo box and then the rest of the fields to
automatically fill when that even is selected, to display the price and
location for that event.

I have entered the following code in the Control source box
=[Event].[Column](0) and then the following code in the Row source box
SELECT
EventName, Event Price FROM Events;

I've set the column widths to 1cm

However I keep getting an error message of Syntax Error (missing
operator)
in query Expression "Event Price"

Can you tell me where I'm going wrong and how to get this form working?

Thanks
 
Ha I'm lost!

Ok so the name of my combo box is event and the name of the field in which I
want the data stored is event and the name of the table in which the
information is stored is Events.

What now?

BruceM said:
If Event is the name of the combo box, this would be the control source of
an unbound text box in which the first column (Column(0) of the combo box
Row Source is to appear:
=[Event].[Column](0)

It is *not* the combo box Control Source. That would be the field in which
you want the selection to be stored.

After you make a selection from a bound combo box (a bound combo box has a
Control Source from the form's Record Source) it will store the data that is
in the bound column, no matter what it displays.

Kels said:
Me again!!!

Sorry, I've fixed these problems, and when I click the box the list of
events appear but I can't select any, I get a message saying "Control
can't
be edited it is bound by
"Kels" wrote: =[Event].[Column](0)

Any ideas how I can fix this?

thanks again ;o)
Hi

I have a table that containts list of events and prices etc.

I have a form based on this table. However, what i want to do is select
the
name of the event from a combo box and then the rest of the fields to
automatically fill when that even is selected, to display the price and
location for that event.

I have entered the following code in the Control source box
=[Event].[Column](0) and then the following code in the Row source box
SELECT
EventName, Event Price FROM Events;

I've set the column widths to 1cm

However I keep getting an error message of Syntax Error (missing
operator)
in query Expression "Event Price"

Can you tell me where I'm going wrong and how to get this form working?

Thanks
 
If it was me I would give the combo box a different name than the field. It
helps avoid confusion to do it that way. I will call the combo box
cboEvent. It is bound to the Event field in tblEvents (I am using the
prefix to identify it as a table). That is, the form has tblEvents as its
Record Source. cboEvent has the field Event as its Control Source.

Pretty much anything on a form (text box, combo box, label, line, etc.) is a
Control. Some controls such as text boxes, combo boxes, check boxes, and a
few other may be bound to a field in the Record Source. That is what is
meant by "bound control". In teh case of the combo box control named
cboEvent its Control Source is the Event field. Just clarifying, if needed,
the basis of the terminology.

The Row Source for a combo box (or list box) establishes what you see when
you click the down arrow, along with other fields related to the one you can
see. The Row Source for cboEvent is:
SELECT [EventName], [Event Price] FROM tblEvents ORDER BY [EventName]
On the combo box Property Sheet you should have the Column Count set to 2.
The column widths can be something like 1.5",.5" if you want to see both the
EventName and the EventPrice in the drop-down list. If you want to see just
the event name they may be 1.5",0".
Select Event as the cboEvent Control Source. Set the Bound Column
(EventName) to 1. All of these selections and settings are on the Property
Sheet. Just to be clear, the Property Sheet is the box with five tabs
(Format, Data, Event, etc.) that you see when you click the combo box in
design view and click View >> Properties (or right click and select
Properties).

In an unbound text box, set the Control Source to:
=[cboEvent].Column(1)
This will display the EventPrice in the text box. The value will not be
stored. If you need to store the price (because it may change in the
future, and you want to know what the price was at the time the record was
created) you will need to take another route to storing the price. I won't
get into that unless it's needed.

Note that in the =[cboEvent].Column(1) the column count starts on 0, so
with (1) you are referencing the second column. Column(0) is the first
column. However, on the Property Sheet the first column (the one you
selected as the Bound Column) is 1. It's a bit confusing at first.



Kels said:
Ha I'm lost!

Ok so the name of my combo box is event and the name of the field in which
I
want the data stored is event and the name of the table in which the
information is stored is Events.

What now?

BruceM said:
If Event is the name of the combo box, this would be the control source
of
an unbound text box in which the first column (Column(0) of the combo box
Row Source is to appear:
=[Event].[Column](0)

It is *not* the combo box Control Source. That would be the field in
which
you want the selection to be stored.

After you make a selection from a bound combo box (a bound combo box has
a
Control Source from the form's Record Source) it will store the data that
is
in the bound column, no matter what it displays.

Kels said:
Me again!!!

Sorry, I've fixed these problems, and when I click the box the list of
events appear but I can't select any, I get a message saying "Control
can't
be edited it is bound by
"Kels" wrote: =[Event].[Column](0)

Any ideas how I can fix this?

thanks again ;o)

Hi

I have a table that containts list of events and prices etc.

I have a form based on this table. However, what i want to do is
select
the
name of the event from a combo box and then the rest of the fields to
automatically fill when that even is selected, to display the price
and
location for that event.

I have entered the following code in the Control source box
=[Event].[Column](0) and then the following code in the Row source box
SELECT
EventName, Event Price FROM Events;

I've set the column widths to 1cm

However I keep getting an error message of Syntax Error (missing
operator)
in query Expression "Event Price"

Can you tell me where I'm going wrong and how to get this form
working?

Thanks
 
[Event Price]
If a field name has a space in it, it must be enclosed with square brackets.
I stopped using spaces a long time ago since "field name" and "field name"
look a lot alike at 3:00AM
 
Thanks, I've made sure all the settings in the property box are as you say
and i'm still getting the same message...hmmm wonder where I'm going wrong!

Mike Painter said:
[Event Price]
If a field name has a space in it, it must be enclosed with square brackets.
I stopped using spaces a long time ago since "field name" and "field name"
look a lot alike at 3:00AM

Hi

I have a table that containts list of events and prices etc.

I have a form based on this table. However, what i want to do is
select the name of the event from a combo box and then the rest of
the fields to automatically fill when that even is selected, to
display the price and location for that event.

I have entered the following code in the Control source box
=[Event].[Column](0) and then the following code in the Row source
box SELECT EventName, Event Price FROM Events;

I've set the column widths to 1cm

However I keep getting an error message of Syntax Error (missing
operator) in query Expression "Event Price"

Can you tell me where I'm going wrong and how to get this form
working?

Thanks
 
Check my response. I explained a number of things in some detail. I
believe you are using the wrong Control Source for your combo box. I think
you are using an expression, when what you need is a field from the form's
record source.

Kels said:
Thanks, I've made sure all the settings in the property box are as you say
and i'm still getting the same message...hmmm wonder where I'm going
wrong!

Mike Painter said:
[Event Price]
If a field name has a space in it, it must be enclosed with square
brackets.
I stopped using spaces a long time ago since "field name" and "field
name"
look a lot alike at 3:00AM

Hi

I have a table that containts list of events and prices etc.

I have a form based on this table. However, what i want to do is
select the name of the event from a combo box and then the rest of
the fields to automatically fill when that even is selected, to
display the price and location for that event.

I have entered the following code in the Control source box
=[Event].[Column](0) and then the following code in the Row source
box SELECT EventName, Event Price FROM Events;

I've set the column widths to 1cm

However I keep getting an error message of Syntax Error (missing
operator) in query Expression "Event Price"

Can you tell me where I'm going wrong and how to get this form
working?

Thanks
 
Back
Top