Running a query using a command button

G

Guest

I have a table. The records have a bunch of data, including a date.

I created a crosstab query to summarize statistical information for all records in the table.

I now want to create a form that displays the results of the crosstab query. The form has controls that are bound to the query fields. However, I want to limit the records used in the crosstab query to a specific date range selected by the user. On my form I have two calendar controls, one for the start date and one for the end date. I have a command button and when the button is clicked it should run the crosstab query but the query should only use records that are within the specified date range. How can I do this?

Here's the code I've written so far:

Option Explicit

Private StartDate As Date
Private EndDate As Date

Private Sub cmdTest_Click()
Dim strTest

'Get date values and put into variables
StartDate = calStartDate.Value
EndDate = calEndDate.Value

'Do some error handling once I get the query stuff figured out

'Test - is the date correct? It better be...
strTest = "Start Date: " & StartDate & vbCrLf & "End Date: " & EndDate
Call MsgBox(strTest)

'Run the crosstab query here, using dates to select specific records
'?????
End Sub


Thanks in advance.

Evan
 
B

BrainlordMesomorph

you're working too hard.

The crosstab query should have critera limiting to the dates in the
calendar form. somthing like:

Between Forms!myForm.CalStartDate and Forms!myform.calendDate

then the button just requerys the form:

me.requery

When you 1st open the form it will show no records, (because the dates
are null) click 2 dates, click the button, ta daa!

hth,
blm
 

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