Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
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 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 April 24th, 2008, 04:53 AM
Authorized User
 
Join Date: Jun 2007
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Searching Multiple Columns in Acess

Hi,

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
example
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?

Thanks

 
Old April 24th, 2008, 11:37 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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

AddressTable
AddressID
AddressInfo1
...


Appointment
AppID
AddressID
Date
Info...

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
Loop

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.

HTH

mmcdonal

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





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





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