PC Review


Reply
Thread Tools Rate Thread

Adding a value to the rowsource of a combo box

 
 
=?Utf-8?B?UklQ?=
Guest
Posts: n/a
 
      23rd Jun 2005
I know this is getting old, but please bare with me...

This is the SQL Statement that is currently on my form's model combo box row
source:

SELECT tblModel.model, tblModel.bstyle, tblModel.engine FROM tblMake RIGHT
JOIN tblModel ON tblMake.make=tblModel.make WHERE
(((tblMake.make)=forms!frmInventory!Make)) ORDER BY tblModel.model;

It works perfect, but I would like to add a "<Add New>" value to the list
generated by this query. I tried adding the "<Add New>" directly to the
table, but it keeps getting filtered out by the criteria of the query.

Eventhough I am not familiar with SQL syntax, I tried using a UNION query.
I used the following statement:

SELECT tblModel.model, tblModel.bstyle, tblModel.engine FROM tblMake RIGHT
JOIN tblModel ON tblMake.make=tblModel.make WHERE
(((tblMake.make)=forms!frmInventory!Make)) ORDER BY tblModel.model UNION
SELECT "<Add New>", NULL, NULL, FROM tblModel;

Needless to say, I am getting syntax errors out the wazoo...

Thanks in advance for all the help you guyz have given me...
Walter



 
Reply With Quote
 
 
 
 
=?Utf-8?B?S2xhdHV1?=
Guest
Posts: n/a
 
      23rd Jun 2005
I have seen questions on this before, but I don't know if there is a way to
do that. (It would be nice). I think the easiest way to do this is to use
the NotInList event of the Combo box so that if a user types in a value not
in the query, it will present a message box asking if they want to add a new
record. If they do, go to a rew record and carry on from there.

"RIP" wrote:

> I know this is getting old, but please bare with me...
>
> This is the SQL Statement that is currently on my form's model combo box row
> source:
>
> SELECT tblModel.model, tblModel.bstyle, tblModel.engine FROM tblMake RIGHT
> JOIN tblModel ON tblMake.make=tblModel.make WHERE
> (((tblMake.make)=forms!frmInventory!Make)) ORDER BY tblModel.model;
>
> It works perfect, but I would like to add a "<Add New>" value to the list
> generated by this query. I tried adding the "<Add New>" directly to the
> table, but it keeps getting filtered out by the criteria of the query.
>
> Eventhough I am not familiar with SQL syntax, I tried using a UNION query.
> I used the following statement:
>
> SELECT tblModel.model, tblModel.bstyle, tblModel.engine FROM tblMake RIGHT
> JOIN tblModel ON tblMake.make=tblModel.make WHERE
> (((tblMake.make)=forms!frmInventory!Make)) ORDER BY tblModel.model UNION
> SELECT "<Add New>", NULL, NULL, FROM tblModel;
>
> Needless to say, I am getting syntax errors out the wazoo...
>
> Thanks in advance for all the help you guyz have given me...
> Walter
>
>
>

 
Reply With Quote
 
John Spencer (MVP)
Guest
Posts: n/a
 
      23rd Jun 2005
Too many commas in the second SELECT clause.
ORDER BY applies at the end of the last query only

Try

SELECT tblModel.model, tblModel.bstyle, tblModel.engine FROM tblMake RIGHT
JOIN tblModel ON tblMake.make=tblModel.make WHERE
(((tblMake.make)=forms!frmInventory!Make))
UNION
SELECT "<Add New>", NULL, NULL FROM tblModel
ORDER BY model;

RIP wrote:
>
> I know this is getting old, but please bare with me...
>
> This is the SQL Statement that is currently on my form's model combo box row
> source:
>
> SELECT tblModel.model, tblModel.bstyle, tblModel.engine FROM tblMake RIGHT
> JOIN tblModel ON tblMake.make=tblModel.make WHERE
> (((tblMake.make)=forms!frmInventory!Make)) ORDER BY tblModel.model;
>
> It works perfect, but I would like to add a "<Add New>" value to the list
> generated by this query. I tried adding the "<Add New>" directly to the
> table, but it keeps getting filtered out by the criteria of the query.
>
> Eventhough I am not familiar with SQL syntax, I tried using a UNION query.
> I used the following statement:
>
> SELECT tblModel.model, tblModel.bstyle, tblModel.engine FROM tblMake RIGHT
> JOIN tblModel ON tblMake.make=tblModel.make WHERE
> (((tblMake.make)=forms!frmInventory!Make)) ORDER BY tblModel.model UNION
> SELECT "<Add New>", NULL, NULL, FROM tblModel;
>
> Needless to say, I am getting syntax errors out the wazoo...
>
> Thanks in advance for all the help you guyz have given me...
> Walter

 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      23rd Jun 2005
=?Utf-8?B?UklQ?= <(E-Mail Removed)> wrote in
news:0EBC1DE9-04F8-4D2F-9D76-(E-Mail Removed):

> It works perfect, but I would like to add a "<Add New>" value to the
> list generated by this query. I tried adding the "<Add New>" directly
> to the table, but it keeps getting filtered out by the criteria of the
> query.


Easy way: use a UNION to add an extra row to the result set:

SELECT tblModel.model,
tblModel.bstyle,
tblModel.engine
FROM tblMake
RIGHT JOIN tblModel
ON tblMake.make=tblModel.make
WHERE tblMake.make=forms!frmInventory!Make
ORDER BY tblModel.model

UNION

SELECT "<Add new>", NULL, NULL, NULL

I think that in older versions of Jet you have to have a FROM clause so
you'll need a line at the bottom like FROM tblModel

The A-level way is to use a List Box Function, which is incredibly
satisfying when it goes right (tee hee) -- fully documented in the Help
files.

All the best


Tim F


 
Reply With Quote
 
=?Utf-8?B?UklQ?=
Guest
Posts: n/a
 
      24th Jun 2005
John,

Eliminating the extra commas did the trick...

Thank U
Walter

"John Spencer (MVP)" wrote:

> Too many commas in the second SELECT clause.
> ORDER BY applies at the end of the last query only
>
> Try
>
> SELECT tblModel.model, tblModel.bstyle, tblModel.engine FROM tblMake RIGHT
> JOIN tblModel ON tblMake.make=tblModel.make WHERE
> (((tblMake.make)=forms!frmInventory!Make))
> UNION
> SELECT "<Add New>", NULL, NULL FROM tblModel
> ORDER BY model;
>
> RIP wrote:
> >
> > I know this is getting old, but please bare with me...
> >
> > This is the SQL Statement that is currently on my form's model combo box row
> > source:
> >
> > SELECT tblModel.model, tblModel.bstyle, tblModel.engine FROM tblMake RIGHT
> > JOIN tblModel ON tblMake.make=tblModel.make WHERE
> > (((tblMake.make)=forms!frmInventory!Make)) ORDER BY tblModel.model;
> >
> > It works perfect, but I would like to add a "<Add New>" value to the list
> > generated by this query. I tried adding the "<Add New>" directly to the
> > table, but it keeps getting filtered out by the criteria of the query.
> >
> > Eventhough I am not familiar with SQL syntax, I tried using a UNION query.
> > I used the following statement:
> >
> > SELECT tblModel.model, tblModel.bstyle, tblModel.engine FROM tblMake RIGHT
> > JOIN tblModel ON tblMake.make=tblModel.make WHERE
> > (((tblMake.make)=forms!frmInventory!Make)) ORDER BY tblModel.model UNION
> > SELECT "<Add New>", NULL, NULL, FROM tblModel;
> >
> > Needless to say, I am getting syntax errors out the wazoo...
> >
> > Thanks in advance for all the help you guyz have given me...
> > Walter

>

 
Reply With Quote
 
=?Utf-8?B?UklQ?=
Guest
Posts: n/a
 
      24th Jun 2005
Tim,

Thank you also for your input... The way you broke down the statement
shined alot of light on my understanding of the syntax...

Thank U
Walter

"Tim Ferguson" wrote:

> =?Utf-8?B?UklQ?= <(E-Mail Removed)> wrote in
> news:0EBC1DE9-04F8-4D2F-9D76-(E-Mail Removed):
>
> > It works perfect, but I would like to add a "<Add New>" value to the
> > list generated by this query. I tried adding the "<Add New>" directly
> > to the table, but it keeps getting filtered out by the criteria of the
> > query.

>
> Easy way: use a UNION to add an extra row to the result set:
>
> SELECT tblModel.model,
> tblModel.bstyle,
> tblModel.engine
> FROM tblMake
> RIGHT JOIN tblModel
> ON tblMake.make=tblModel.make
> WHERE tblMake.make=forms!frmInventory!Make
> ORDER BY tblModel.model
>
> UNION
>
> SELECT "<Add new>", NULL, NULL, NULL
>
> I think that in older versions of Jet you have to have a FROM clause so
> you'll need a line at the bottom like FROM tblModel
>
> The A-level way is to use a List Box Function, which is incredibly
> satisfying when it goes right (tee hee) -- fully documented in the Help
> files.
>
> All the best
>
>
> Tim F
>
>
>

 
Reply With Quote
 
=?Utf-8?B?UklQ?=
Guest
Posts: n/a
 
      24th Jun 2005
Klatuu,

I am familiar with utilizing the On Not In List event, I wanted to learn
how the SQL Statement works, which is a little more complicated... Thats why
I wanted to add the <Add New> to the value list of the control.

Thank U also for ur input...

Walter

"Klatuu" wrote:

> I have seen questions on this before, but I don't know if there is a way to
> do that. (It would be nice). I think the easiest way to do this is to use
> the NotInList event of the Combo box so that if a user types in a value not
> in the query, it will present a message box asking if they want to add a new
> record. If they do, go to a rew record and carry on from there.
>
> "RIP" wrote:
>
> > I know this is getting old, but please bare with me...
> >
> > This is the SQL Statement that is currently on my form's model combo box row
> > source:
> >
> > SELECT tblModel.model, tblModel.bstyle, tblModel.engine FROM tblMake RIGHT
> > JOIN tblModel ON tblMake.make=tblModel.make WHERE
> > (((tblMake.make)=forms!frmInventory!Make)) ORDER BY tblModel.model;
> >
> > It works perfect, but I would like to add a "<Add New>" value to the list
> > generated by this query. I tried adding the "<Add New>" directly to the
> > table, but it keeps getting filtered out by the criteria of the query.
> >
> > Eventhough I am not familiar with SQL syntax, I tried using a UNION query.
> > I used the following statement:
> >
> > SELECT tblModel.model, tblModel.bstyle, tblModel.engine FROM tblMake RIGHT
> > JOIN tblModel ON tblMake.make=tblModel.make WHERE
> > (((tblMake.make)=forms!frmInventory!Make)) ORDER BY tblModel.model UNION
> > SELECT "<Add New>", NULL, NULL, FROM tblModel;
> >
> > Needless to say, I am getting syntax errors out the wazoo...
> >
> > Thanks in advance for all the help you guyz have given me...
> > Walter
> >
> >
> >

 
Reply With Quote
 
Tim Ferguson
Guest
Posts: n/a
 
      24th Jun 2005
=?Utf-8?B?UklQ?= <(E-Mail Removed)> wrote in news:BDF99838-
4354-4899-BA4E-(E-Mail Removed):

> The way you broke down the statement
> shined alot of light on my understanding of the syntax...


The one thing that I HATE about Access's SQL designer is the way it refuses
to format the command; and often it seems trash a laid-out command
deliberately. SQL does not have to be a human-unreadable language, rather
the reverse, in fact.

All the best


Tim F



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RowSource of Combo Dependent another Combo Stu Microsoft Access Form Coding 2 1st Aug 2008 10:10 PM
Combo box rowsource based on another combo box BonnieW via AccessMonster.com Microsoft Access Form Coding 3 24th Aug 2007 12:08 AM
Combo RowSource Bill Microsoft Access Form Coding 2 31st Jul 2006 01:05 AM
One combo generating rowsource for second combo =?Utf-8?B?RGFu?= Microsoft Access Forms 1 19th May 2005 01:43 AM
rowsource for combo box =?Utf-8?B?ZGltd2l0?= Microsoft Access VBA Modules 2 9th Sep 2004 10:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:57 AM.