working with combo boxes

C

Calvin

I have a group of combo boxes with embedded values from
tables. Users can search based on their criteria. One
of the boxes is search by date. I have the values like
JANUARY, FEBRUARY...DECEMBER, 1ST QUARTER...4TH QUARTER.
My problem is how do I include JANUARY to MARCH when a
user picks 1ST QUARTER as the criteria. So that the
records with JAN, FEB, MAR and 1ST QUARTER will show.

Thanks
 
J

John Vinson

I have a group of combo boxes with embedded values from
tables. Users can search based on their criteria. One
of the boxes is search by date. I have the values like
JANUARY, FEBRUARY...DECEMBER, 1ST QUARTER...4TH QUARTER.
My problem is how do I include JANUARY to MARCH when a
user picks 1ST QUARTER as the criteria. So that the
records with JAN, FEB, MAR and 1ST QUARTER will show.

Thanks

What's the structure of the data in your table? Do you have a field
containing a text string "MAY" or (in the next record) "2ND QUARTER"?
If so... ouch!!
 
C

CALVIN

I have 2 fields in the table

tdateID tdate
1 January
2 February
3 March
... ..
13 1st Quarter
14 2nd Quarter


Thanks.
 
J

John Vinson

tdateID tdate
1 January
2 February
3 March
.. ..
13 1st Quarter
14 2nd Quarter


Thanks.

This will be more than a bit difficult, since '1ST QUARTER' is just a
string with no computer-meaningful relationship to other strings such
as 'January'. YOU know it's a date range - the computer doesn't!

What you'll need to do is create VBA code to construct a valid SQL
string in the afterupdate event of the textbox; air code here...

Private Sub cboFindDate_AfterUpdate()
Dim strSQL As String
Dim strCrit As String
strSQL = "SELECT <whatever> FROM <whereever> WHERE tdate IN ("
Select Case cboFindDate
Case "1st Quarter"
strSQL = strSQL & "'January', 'February', 'March')"
Case "2nd Quarter"
strSQL = strSQL & "'April', 'May', 'June'"
Case "2nd Quarter"
strSQL = strSQL & "'July', 'August', 'September')"
Case "2nd Quarter"
strSQL = strSQL & "'October', 'November', 'December')"
Case Else
strSQL = strSQL & "'" & cboFindDate & "')" ' just put in month
End Select

You could then assign strSQL as the Recordsource of a form or report
to find and display the data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top