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
| 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
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 24th, 2008, 04:53 AM
Authorized User
Join Date: Jun 2007
Location: , , .
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Searching Multiple Columns in Acess


I am trying to workout a way that I can run a query that will search a number of columns and bring me the latest date back for that id number
AddressID Appt1 Appt2 Appt3 Appt4 Appt5
101 07/04/2008 14/04/2008 22/04/2008 01/05/2008
102 06/04/2008 13/04/2008 21/04/2008 23/04/2008 08/05/2008

So what I am trying to understand is in my query I want to add another column thats say MaxAppt and that would look accross the fileds and pick out the latest Appt dates... (in this case would be 01/05/2008 & 08/05/2008)

How can this be done?


Reply With Quote
  #2 (permalink)  
Old April 24th, 2008, 11:37 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

This is a design issue. You should be using two tables like this:



Then you would just do a MAX() on the query results.

Is there a reason you need a table structured the way you have it?

Anyway, on your data entry form, put down all of your fields, including the MAX field.

Then on the Before Insert AND on the Before Update event of the form, put this code:

Dim DateArray As Variant
Dim dtMax As Variant
Dim dtTest As Variant
Dim i As Integer

i = 0

DateArray = Array(Me.Date1, Me.Date2, Me.Date3, Me.Date4, Me.Date5)
dtTest = DateArray(i)
dtMax = DateArray(i)
i = i + 1
Do Until i = 5
    dtTest = DateArray(i)
    If dtTest > dtMax Then
        dtMax = dtTest
    End If
i = i + 1

Me.MaxDate = dtMax

I got this to work but it is a little flakey. See, all this code since the underlying database design is flawed. I am sure there is a more elegant way to do this, besides the redesign.



Look it up at: http://wrox.books24x7.com
Reply With Quote

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
Problem in searching multiple keywords kumiko Classic ASP Basics 2 April 3rd, 2008 08:12 PM
Searching multiple tables melkin Classic ASP Databases 0 March 10th, 2008 11:48 AM
Searching Multiple Sheets for Data? Bill_L Excel VBA 2 June 20th, 2007 09:14 AM
multiple checkbox columns mariag BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 June 4th, 2007 03:06 PM
Multiple Columns in an Index owain Access 2 June 16th, 2003 12:15 PM

All times are GMT -4. The time now is 12:06 PM.

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