Link to home
Start Free TrialLog in
Avatar of Scotto123
Scotto123

asked on

Form with comboboxes to allow selection of date fields for reporting

I have these date fields in my database.  

ConsultDate
InitialSim
VSimSchedule
FusionComplete
NormalContourComplete
MDContourComplete
MDFieldsDrawn
DosimetryComplete
MDApprov
PhysicsApprov

I want to create a form that will allow the user to select data using comparison of date1 to date2 and put that data into a report. So, the user may want to calculate difference between ConsultDate and MDApprov or maybe VSimSchedule and DosimetryComplete.  

Is there a way to have the fields be selectable in comboboxes and calculate the difference?
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

<Is there a way to have the fields be selectable in comboboxes and calculate the difference? >
Yes..
set the rowsource of your combo box with

select ConsultDate,InitialSim,VSimSchedule,FusionComplete,NormalContourComplete,MDContourComplete,MDFieldsDrawn,DosimetryComplete,MDApprov,PhysicsApprov
From YourTable

difference is calculated by the DateDiff() function, something like this

* difference between ConsultDate and MDApprov
DateDiff("d",me.combo.column(0),me.combo.column(8))
Have 2 combo boxes: cbo1, cb2
Control rowsource: Qyery/Table : SELECT datfield from tble;

select date1 from cbo1 and date2 from cbo2

in report: textBoxDate: = Forms:theOpenForm!cbo2 - Forms:theOpenForm!cbo1

You may test which is supposed to be greater cno1 or cbo2
You may filter cbo2 to include dates greater than the selected date in cbo1. by adding a where close.
Avatar of Scotto123
Scotto123

ASKER

Maybe I wasn't specific enough.  Or I just don't get it.  

I want to have only 2 comboboxes on the form.  I want to be able to select which field the query will calculate.  So in cbx1 I want a list of the posible fields and cbx2 I want a list of the posible fields.

If I select ConsultDate in cbx1 and MDApprov in cbx2 I want to calculate the difference.  
Is this what you have above?
I set the combobox to

set the rowsource of your combo box with

select ConsultDate,InitialSim,VSimSchedule,FusionComplete,NormalContourComplete,MDContourComplete,MDFieldsDrawn,DosimetryComplete,MDApprov,PhysicsApprov
From YourTable

So when I open the drop down list I get a date from my first field.  I want to have a list of fields to select from.
using two combo boxes

* difference between ConsultDate and MDApprov
DateDiff("d",me.cbx1,me.cbx2)
I want the user to be able to select which date fields they want to calculate.
Here is how I am seeing it.
Date-Selection-Form.jpg
to have the names of the fields shown in the combo box
set
Row source type  Field lists
Row Source         NameOf the table
Got it.  Now how do I calculate the difference?
To get the difference in days, just use:
date2-date1
If you set the control source in the same form to cbo2 - cbo1 it displays the difference in days.
To use it in a report, add the qualifying path to the form: Forms!formName!cbo2 - Forms!formName!cbo1

For days, or other formats you may use DateDiff ("interval", date1, date2)
Interval includes: day, month, ... seconds. For days use d, check help on DateDiff for a list of available intervals.
The values in the Comboboxes are not dates - they are the date field names.  

I tried this but it doesn't work:

Dim SQL As String
Dim SelFields As Variant
   
SelFields = [" + Me.Combo1 + "]

SQL = "Select " & SelFields & " from [BoardData]"
I see! It can be done.
Can you upload a sample database, and state one example of expected result after selecting from combo boxes?
I want to calculate the difference between InitialSim and MDContourComplete and populate this in a query.  The result for the one record I have is 26 days.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK, Cap.  I like it!  

As I stated in my question, I need to pull this data in a report (or query for report record source).  Can I pull the same info for all records in a query to I can generate a report.
Or how about the form pushes the data to a temp table?  I'm looking at the code - it's awesome.  I just cant figure how to get it in a query.