Solved

Append query based on combo box selection

Posted on 2003-10-27
5
488 Views
Last Modified: 2012-06-27
Hello all,

I need to run an Append query based on the results of a combo box selection.

I've almost done it but not quite - so I'm hoping there's an expert out there who can tell me what I am doing wrong !

The situation is as follows.....

I have got a subform off a main form which itself has got two subforms on it based on two different tables.  The first subform has a combo box which is bound and does a lookup to yet another table if it needs to be changed.

I need to update a field in the second subform with the results from my combo box selection - after update of the combo.

I have written an update query to run After Update which nearly does it...............

INSERT INTO LifeHistory ( PolicyID, CallDate, CallTime, Subject )
SELECT [Forms]![frmNEWMAIN]![Life]![PolcyID] AS PolicyID, Date() AS CallDate,
Time() AS CallTime, [Forms]![frmNEWMAIN]![Life]![StateID] AS Subject;

What this does, is update my Subject field with the StateID as a number - but what I really want is what my combo box is displaying which is "tlkpLifeStates.LifeStateText" - i.e, results of the lookup the combo is doing - NOT it's corresponding foreign key value.

It's a bit confusing (to me at least) so if you need any more information then please ask.  Otherwise, I'd appreciate the help.......!

Ensor.

0
Comment
Question by:ensor
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:walterecook
ID: 9629537
[Forms]![frmNEWMAIN]![Life]![StateID] will display the value of the Bound Column of the combo box.  You could either
a) change the bound column to the one you want or change the query to this:
[Forms]![frmNEWMAIN]![Life]![StateID].column(2)

Where 2 is the third column in your combo box, for instance.
(Remember 0 is the first column in both examples)

Good luck
Walt
0
 

Author Comment

by:ensor
ID: 9629742
Hi Walt,

I'm not sure how to change the bound column if the fields it is looking up are in a different table.......?

So, I tried hardcoding
[Forms]![frmNEWMAIN]![Life]![StateID].column(2)

but all that gave me was.....
Undefined function '[Forms]![frmNEWMAIN]![Life]![StateID].column' in expression

My combo box works on this....
SELECT DISTINCTROW tlkpLifeStates.*, tlkpLifeStates.LifeStateText
FROM tlkpLifeStates;

Still stuck........

Ensor.
0
 
LVL 17

Accepted Solution

by:
walterecook earned 500 total points
ID: 9630327
The "bound column" property of a text box really just says this:
Whenever you reference this combo, report the value in this column.  So run your query:
SELECT DISTINCTROW tlkpLifeStates.*, tlkpLifeStates.LifeStateText
FROM tlkpLifeStates;
If it shows this:
Field1, field2, LifeStateText
1           a          AZ
2            B         NY

If the bound column is 0 the combobox value is 1
If the bound column is 1 the combobox value is a
If the bound column is 2 the combobox value is AZ

See?
Hope that helps
Walt


0
 

Author Comment

by:ensor
ID: 9632196
Thanks Walt - you've shown me the error of my ways.  My problem was down to the combo box also having it's Control Source as the StateID - which of course was a number - hence when I tried to bound it to a text field it didn't like it.  

Your advice has shown me what I really should be doing in this box.  

Thankyou...

Ensor.
0
 
LVL 17

Expert Comment

by:walterecook
ID: 9633507
Good for you.  Glad you got it going.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Get the ms access version 4 34
subform does update on ms/access 2 17
DCount using "OR" 4 19
Search field on a form 7 17
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now