Jumat, 17 Juli 2020

Re: [MSAccessProfessionals] Access report, need to pass parameters to SQL Server back end

hi Wei,

Perhaps before you open the report, make sure you save the record if it is dirty?

kind regards,
crystal

On 7/17/2020 12:56 PM, Wei Qian via groups.io wrote:
I put the following code in the form's OK button, click event, using Duane's function.  The query property changed as I wanted, but I will got an error saying"run time error 2585.  This action can not be carried out while processing a form or report event" after clicking OK, and debug will lead to the last line code of DoCmd.OpenReport.  The report sometimes does run if I close out and stop the debugger, sometimes doesn't.  I googled and it seems this is the command to open the report. I don't have front end programming experience. What did I do wrong?

Thanks very much!

~ Wei

Private Sub OK_Click()
 
Dim strSQL As String
Dim strOldSQL As String
 
strSQL = "SELECT * FROM vWorkOrders " & _
    "WHERE MaxOfReleaseDate BETWEEN '" & Me.txtStart & "' AND '" & _
    Me.txtEnd & "' "
      
  If Not IsNull(Me.cbQRFType) Then
    strSQL = strSQL & " AND QRFTypeDescr = '" & Me.cbQRFType & "' "
  End If
  
  If Not IsNull(Me.txtClassCode) Then
    strSQL = strSQL & " AND Class = '" & Me.txtClassCode & "' "
  End If
      
strSQL = strSQL & "ORDER BY [SN/LotStart], WorkOrderNo;"
  
strOldSQL = fChangeSQL("Instruments Query", strSQL)
 
DoCmd.OpenReport ReportName:="Instruments Detail Report"
 
 
End Sub

Tidak ada komentar:

Posting Komentar