someone plz help me with this vba coding!!!!!

shy216

New member
Local time
Today, 04:57
Joined
Jul 12, 2005
Messages
7
trying to make it so that when you open the report, it'll pop a dialog box for users to choose the dates (from date to to date. ie. 04/15/05 to 07/17/05). When I click on the report, dialog shows up fine but it finds every record... can someone please help me with this.

here's the coding for the report

Option Compare Database
Option Explicit

Public Sub cmdCancel_Click()
' Method in all forms to allow clean close
DoCmd.Close acForm, Me.Name
End Sub


Private Sub cmdPrint_Click()
' Validate the dates
If Not IsDate(Me.txtFromDate) Then
Me.txtFromDate.SetFocus
MsgBox "You must enter a valid From date.", vbCritical, gstrAppTitle
Exit Sub
End If
If Not IsDate(Me.txtToDate) Then
Me.txtToDate.SetFocus
MsgBox "You must enter a valid To date.", vbCritical, gstrAppTitle
Exit Sub
End If
If Me.txtFromDate > Me.txtToDate Then
Me.txtFromDate.SetFocus
MsgBox "The From date must be less than or equal to the To date.", _
vbCritical, gstrAppTitle
Exit Sub
End If
' Hide me so the calling report can run
Me.Visible = False

End Sub

Private Sub cmdToDateCal_Click()
Dim varReturn As Variant
' Clicked the calendar icon asking for graphical help
' Put the focus on the control to be updated
Me.txtToDate.SetFocus
' Call the get a date function - date only
varReturn = GetDate(Me.txtToDate, True)
End Sub

Private Sub Form_Open(Cancel As Integer)
' Set up the form caption
Me.Caption = Me.OpenArgs
' Set up the label
Me.lblTitle.Caption = "Select Dates for " & Me.OpenArgs
End Sub



and coding for the form i designed.

Option Compare Database
Option Explicit

Public Sub cmdCancel_Click()
' Method in all forms to allow clean close
DoCmd.Close acForm, Me.Name
End Sub

Private Sub cmdFromDateCal_Click()
Dim varReturn As Variant
' Clicked the calendar icon asking for graphical help
' Put the focus on the control to be updated
Me.txtFromDate.SetFocus
' Call the get a date function - date only
varReturn = GetDate(Me.txtFromDate, True)
End Sub

Private Sub cmdPrint_Click()
' Validate the dates
If Not IsDate(Me.txtFromDate) Then
Me.txtFromDate.SetFocus
MsgBox "You must enter a valid From date.", vbCritical, gstrAppTitle
Exit Sub
End If
If Not IsDate(Me.txtToDate) Then
Me.txtToDate.SetFocus
MsgBox "You must enter a valid To date.", vbCritical, gstrAppTitle
Exit Sub
End If
If Me.txtFromDate > Me.txtToDate Then
Me.txtFromDate.SetFocus
MsgBox "The From date must be less than or equal to the To date.", _
vbCritical, gstrAppTitle
Exit Sub
End If
' Hide me so the calling report can run
Me.Visible = False

End Sub

Private Sub Form_Open(Cancel As Integer)
' Set up the form caption
Me.Caption = Me.OpenArgs
' Set up the label
Me.lblTitle.Caption = "Select Dates for " & Me.OpenArgs
End Sub


codings from Microsoft "Building Access Applications"
viescas

any kind of help would be appreciated
 
Either your report is running before the dates are chosen, or your Query the report is based on is not picking up the dates properly from the form or you are suppose to initiate the report from your cmdPrint_Click() sub and it is not being intiated there, but that would go back to the first one.
When you click the button to open this, what exactly happens? Since you are getting a report, when is it running?
 
thx ^^

i got it! forgot to set my control source as my query ^^ thx
 
Shy,
Instead of working from the report, work from the form. You probably have a form with 2 unbound text boxes to enter the dates. Call the form first and add a button to call the report. Do all your validation in the form.
 

Users who are viewing this thread

Back
Top Bottom