how to use a date range to limit the results of a query

G

Guest

Hi
I have two pop up calendars that allow the user to choose a date range on a
form along with a list box of diagnosis. The purpose of the form is to find
multiple laboratory values that were drawn during a certain time range. This
form is linked to run a query. The code is as follows:

Option Compare Database
Option Explicit
Dim cboOriginator As ComboBox
Private Sub calendar_Click()
cbostartdate.Value = calendar.Value
cbostartdate.SetFocus
calendar.Visible = False

End Sub

Private Sub calendar2_Click()
cboEndDate.Value = calendar2.Value
cboEndDate.SetFocus
calendar2.Visible = False

End Sub

Private Sub cboEndDate_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Set cboOriginator = cbostartdate
calendar2.Visible = True
calendar2.SetFocus
If Not IsNull(cboOriginator) Then
calendar2.Value = cboOriginator.Value
Else
calendar2.Value = Date
End If
End Sub

Private Sub cbostartdate_MouseDown(Button As Integer, Shift As Integer, X As
Single, Y As Single)
calendar.Visible = True
calendar.SetFocus
If Not IsNull(cbostartdate) Then
calendar.Value = cbostartdate.Value
Else
calendar.Value = Date
End If
End Sub

Private Sub cmdcancel_Click()
DoCmd.Close acForm, "frmLabs"
End Sub

Private Sub cmdOK_Click()

End Sub
Private Sub labcmd_Click()
On Error GoTo Err_labcmd_Click

Dim stDocName As String

stDocName = "qrylabs"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_labcmd_Click:
Exit Sub

Err_labcmd_Click:
MsgBox Err.Description
Resume Exit_labcmd_Click

End Sub
 
J

Jeff L

To do a date range in a query the syntax for the criteria is:
Between Forms!FormName!cboStartDate And Forms!FormName!cboEndDate

Hope that helps!
 

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