Error message

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I get the error message "You canceled the previous operation." when I run the
following code. I can't see or understand why.

Private Sub cmdSchedules_Click()
On Error GoTo Err_cmdSchedules_Click

Dim stDocName As String
Dim strWhere As String

If IsNull(txtOStartDate) = -1 Then
MsgBox "You must enter at starting date!", vbInformation
txtOStartDate.SetFocus
Exit Sub
End If

Me.RecordSource = "SELECT * FROM RPTqryLearnerTop " _
& "WHERE StartDate = 'Me.txtOStartDate'"
strWhere = Me.RecordSource

stDocName = "rptOrientationSchedule"
DoCmd.OpenReport stDocName, acPreview, , strWhere

Exit_cmdSchedules_Click:
Exit Sub

Err_cmdSchedules_Click:
MsgBox Err.Description
Resume Exit_cmdSchedules_Click

End Sub


Thank you, Fay
 
Several issues Fay.

To sort out the problem, temporarily comment out the error handler by adding
a single quote to line 2, i.e.:
'On Error GoTo Err_cmdSchedules_Click
You will then be able to see which line is giving the error.

You need to concatenate the date into the string, and include the #
delimiters:
Me.RecordSource = "SELECT * FROM RPTqryLearnerTop " _
& "WHERE StartDate = " & Format(Me.txtOStartDate, "\#mm/dd/yyyy\#") &
";"

You cannot assign the entire SQL statement for the WhereCondition of the
Open report, so you need:
strWhere = "StartDate = " & Format(Me.txtOStartDate, "\#mm/dd/yyyy\#")

Not sure if you intended >= instead of =.
 
Thank you Allen that worked exactly like I wanted it to.

I need to go into the rest of the story. I have two command buttons going to
the same report, but with each button they filter the material from different
controls. You know the first one that took the date infomration from a text
box. That allows me to grab everyone for a specific date. The other button
gets it's criteria from a unbound listbox. The problem is that when the same
report opens using the listbox as a source it brings up the proper
person/people but the sub reports ususally don't display. I say usually
because if you had previously used the button using the date then the listbox
button displays the subforms.

Here is the code from the second button. Again thank you for your help.

Private Sub cmdIndSchedules_Click()
On Error GoTo Err_cmdIndSchedules_Click

Dim stDocName As String
Dim strWhere1 As String

For Each varItm In lstOrientees.ItemsSelected
strWhere1 = strWhere1 & ", " & Chr(34) &
Me.lstOrientees.ItemData(varItm) & Chr(34)
Next varItm
strWhere1 = "FullName In (" & Mid(strWhere1, 2) & ")"

stDocName = "rptOrientationSchedule"
DoCmd.OpenReport stDocName, acPreview, , strWhere1

Exit_cmdIndSchedules_Click:
Exit Sub

Err_cmdIndSchedules_Click:
MsgBox Err.Description
Resume Exit_cmdIndSchedules_Click

End Sub


Fay
 
Fay, I'm guessing that the query for the subreport is somehow reading the
date--perhaps from the text box--and if the date is not present, the
subreport would then show nothing?
 
Du..... Stupid. Thanks for the direction, sometimes I have trouble seeing the
forest because there are trees in the way. Fay
 
Back
Top