Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 28th, 2004, 12:05 AM
Authorized User
 
Join Date: Sep 2003
Location: Melbourne, Victoria, Australia.
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default Populate a drop down from database


I need to populate a drop down box with data from a field where there can be anything from 1 to 95 instances of each possibility
But I only want one of each instance in the drop down

EG:-
Database records
a
bbb
ccccccc
dd
e
ffffffff

I just want to end up with
a
b
c
d
e
ect...

I know it can be done but I cannot get my head around the code

Help anyone ??



Reply With Quote
  #2 (permalink)  
Old November 29th, 2004, 02:44 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: Lehigh Acres, FL, USA.
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

Here is a sample using SUBSTRING
Code:
USE NORTHWIND
SELECT DISTINCT SUBSTRING(FirstName, 1, 1)AS NAME
FROM EMPLOYEES
ORDER BY NAME

Jaime E. Maccou
Applications Analyst
Reply With Quote
  #3 (permalink)  
Old November 29th, 2004, 03:11 AM
Friend of Wrox
 
Join Date: Nov 2003
Location: Lehigh Acres, FL, USA.
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

sorry in access you can use this

Code:
SELECT DISTINCT Left$([firstname],1) AS name
FROM EMPLOYEES
ORDER BY Left$([firstname],1);
Jaime E. Maccou
Applications Analyst
Reply With Quote
  #4 (permalink)  
Old November 29th, 2004, 06:13 AM
Authorized User
 
Join Date: Sep 2003
Location: Melbourne, Victoria, Australia.
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the replies but ..
I Used:---

myPath = Server.MapPath("../mydata.mdb")
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.ConnectionTimeout = 15
objDC.CommandTimeout = 30
objDC.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & myPath & ";"

Set objRS = Server.CreateObject("ADODB.Recordset")
 objRS.Open "sheds", objDC, 0, 1

SELECT DISTINCT location FROM sheds

at this point i get

Microsoft VBScript compilation error '800a03fd'

Expected 'Case'

/up/pulldown.asp, line 15

SELECT DISTINCT location FROM sheds
-------^

I am missing something ??

Reply With Quote
  #5 (permalink)  
Old November 29th, 2004, 10:55 AM
Authorized User
 
Join Date: Sep 2003
Location: Melbourne, Victoria, Australia.
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please Ignore the last message..
Your 'DISTINCT' set me on the right path, and I just needed to get my head around the syntax and order of things to get it to work

Thanks for the Help

Topshed

Reply With Quote
  #6 (permalink)  
Old November 29th, 2004, 09:38 PM
Authorized User
 
Join Date: Sep 2003
Location: Melbourne, Victoria, Australia.
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry I am back again, I am using the following

myPath = Server.MapPath("../mydb.mdb")
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.ConnectionTimeout = 15
objDC.CommandTimeout = 30
objDC.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & myPath & ";"
Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT DISTINCT name FROM db4 ORDER BY name"
objRS.Open strSQL, objDC, 0, 1
If Not objRS.EOF Then
    objRS.MoveFirst %>
    <form method="get" action= "<%= strURL %>">
    <select name="search">
    <option>Select Class</option>
    <% Do While Not objRS.EOF %>
    <option value><%= objRS.Fields("name") %></option>
    <% objRS.MoveNext
    Loop %>
   </select>
  <input type="submit" value="Submit Here" />
</form>
<%
End If
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
strSearch = trim(Request.QueryString("search"))
response.write strSearch

Problem is although my pulldown box shows all the info that it should the debug lines at the end always report the result as NULL on Submit.

and further on response.write strSQL results in :-
"SQL statement: SELECT * FROM db4 WHERE name = 'NULL' ORDER BY name;"

What am i Missing _PLEASE HELP

Topshed

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate the 2nd drop down based on value of 1st pendemv Classic ASP Databases 3 August 26th, 2008 12:42 PM
Populate fields from drop-down selection SimonL Infopath 0 April 12th, 2007 07:30 AM
Populate the drop down ashraf.khan Struts 2 August 2nd, 2006 03:06 AM
How to populate drop down box with registery value method Beginning VB 6 2 April 20th, 2006 03:00 AM
populate drop down list with a function code3hree Javascript 1 May 28th, 2005 11:44 AM



All times are GMT -4. The time now is 07:02 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.