Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 17th, 2009, 04:06 AM
Registered User
 
Join Date: Jun 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default ComboBox List Nightmare

Hi all

firstly let me just say thanks a lot for taking the time to read this message, I hope some of you will read this and think "ohhhh this guy is so close with his code, ill just change it abit and he will be happy" rather than "this guy is way off!"

Firstly the simple scenario. (MYSQL Access 2007 VBA)

One table call it tableInfo
About 15/25 columns, but only 3 I am interested in for this example.

Column 1 /2 /3
The all have the same data type of a VarChar(255) assigned to them on my SQL Server.

The are fed different values for the time being from numerous forms etc within the database, its nothing hugely complicated...

However I have a ComboBox List which previously was functioning for Column1. For example if new data was amended to that column after an update you could then choose that item from the combolist.
Simple.

I also read that using the SQL statement UNION you are able to take 2 or more columns of the same time and basically conform them into one. Which is perfect in my scenario as what I want is to be able able take the values from all 3 of the columns and have them listed (in and order I choose) under one ComboBox list.

Code:
SELECT DISTINCT tableInfo.[column1]
FROM tableInfo
UNION SELECT DISTINCT tableInfo.[column2]
FROM tableInfo
ORDER BY 1;
This, for the 2 columns, works perfectly. It takes all the values from the columns and puts it as one. The trouble comes with MY LOGIC and the thinking of adding an addition line to the statement.

Simply adding any addition UNION SELECT DISTINCT before the Order By 1 generates code error.

"Error in your SQL Syntax" < No kidding Mr.SQL give me a chance Im learning!

So I obviously have dug around a lot on the net, there are tonnes of examples of taking info from different tables etc, but havent stumbled across how they deal with more than 2 columns.

Something like this is what I was thinking

Column1
A
B
C

Column2
D
E
F

Column3
G
H
I

Combobox List after SQL Query
1 Column in list only....... Dont want 3 columns.

A
B
C
D
E
F
G
H
I

I know this is a long message and formatted badly, however I am about to embark on another day of coding and cant stand the thought that this is something incredibly simple which I am just missing syntax wise.

Regards to all.

JP
 
Old June 19th, 2009, 11:37 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Without being sure why you want to do this (table design and list structure), and what you are going to do with the selection, it would be hard to say. You can always create a temp table, delete all the data from it, then run 3 append queries from your columns to fill it up, then bind your combo to the temp table when your form opens.

Like, on the On Click event of the button you use to open the form, do this:

Code:
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryDeleteOldData"
DoCmd.OpenQuery "qryAppendColumn1"
DoCmd.OpenQuery "qryAppendColumn2"
DoCmd.OpenQuery "qryAppendColumn3"
DoCmd.SetWarnings True
 
DoCmd.OpenForm...
Or put that on the On Load event of the form. Would that work?

Then on the combo SQL string, put SELECT DISTINCT ... ORDER BY
__________________
mmcdonal

Look it up at: http://wrox.books24x7.com

Last edited by mmcdonal; June 19th, 2009 at 11:39 AM.. Reason: Added more instructions





Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox List Fill Range jani Access VBA 1 July 29th, 2008 05:04 PM
list of values from postgresql to combobox zamir4eva Beginning PHP 1 January 3rd, 2007 11:29 PM
"Are you Sure" Before Dropping List in ComboBox lam2rw Excel VBA 2 September 22nd, 2006 06:57 AM
Dynamic Combobox List Intern06 Pro VB Databases 2 June 29th, 2006 09:41 AM
Combobox that shows what's not in its list Mitch Access 6 September 18th, 2003 11:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.