Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help!!! Cant save as snapshot with where clause, using .Net

vincel2k2vincel2k2 Posts: 1Member
The code below works fine if there is no where clause, but fails if there is a where clause.
I get this error: There was a problem accessing a property or method of the OLE object. On this line: .OpenReport(sReportName, Access.AcView.acViewPreview, , strSQL)

Here's the complete code:
Public Function fGetSnapshot(ByVal sReportName As String)
Dim acApp As Access.Application
Dim myReport As Access.Report
Dim strDBPath As String
Dim StrFileName As String
Dim StrFilePath As String
Dim strSQL As String
Dim strFilter As String
Const acFormatSNP = "Snapshot Format (*.snp)"
Dim sUserName As String
Dim fso
fso = CreateObject("Scripting.FileSystemObject")
strDBPath = Server.MapPath("..YMSReportsDBUltraReporting_SQL.adp")
StrFilePath = Server.MapPath("..YMSReportsDB")

sUserName = Session("username")

acApp = New Access.Application
With acApp
.OpenCurrentDatabase(strDBPath)


strFilter = ""
If cboDiv.SelectedIndex > 0 Then

strSQL = "[tblYardOnly].[YARD_PO_UserField2] = " & cboDiv.SelectedValue
With acApp.DoCmd
If Len(strSQL) > 0 Then
.OpenReport(sReportName, Access.AcView.acViewPreview, , strSQL)
Else
.OpenReport(sReportName, Access.AcView.acViewPreview)
End If

End With
Else
With acApp.DoCmd
.OpenReport(sReportName, Access.AcView.acViewPreview)

End With

End If
' Print the report.
StrFileName = Mid(sUserName, 1, InStr(1, sUserName, "@", CompareMethod.Text) - 1) & sReportName & ".snp"
'if it is already there, delete it
.DoCmd.OutputTo(Access.AcOutputObjectType.acOutputReport, , acFormatSNP, StrFilePath & StrFileName)
End With


acApp.Quit()
acApp = Nothing

Response.Redirect(StrFilePath & StrFileName, False)

End Function



Comments

  • HackmanCHackmanC Posts: 441Member
    : The code below works fine if there is no where clause, but fails if there is a where clause.
    : I get this error: There was a problem accessing a property or method of the OLE object. On this line: .OpenReport(sReportName, Access.AcView.acViewPreview, , strSQL)
    :
    : Here's the complete code:
    : Public Function fGetSnapshot(ByVal sReportName As String)
    : Dim acApp As Access.Application
    : Dim myReport As Access.Report
    : Dim strDBPath As String
    : Dim StrFileName As String
    : Dim StrFilePath As String
    : Dim strSQL As String
    : Dim strFilter As String
    : Const acFormatSNP = "Snapshot Format (*.snp)"
    : Dim sUserName As String
    : Dim fso
    : fso = CreateObject("Scripting.FileSystemObject")
    : strDBPath = Server.MapPath("..YMSReportsDBUltraReporting_SQL.adp")
    : StrFilePath = Server.MapPath("..YMSReportsDB")
    :
    : sUserName = Session("username")
    :
    : acApp = New Access.Application
    : With acApp
    : .OpenCurrentDatabase(strDBPath)
    :
    :
    : strFilter = ""
    : If cboDiv.SelectedIndex > 0 Then
    :
    : strSQL = "[tblYardOnly].[YARD_PO_UserField2] = " & cboDiv.SelectedValue
    : With acApp.DoCmd
    : If Len(strSQL) > 0 Then
    : .OpenReport(sReportName, Access.AcView.acViewPreview, [RED]TRY SOMETHING HERE "" [/RED], strSQL)
    : Else
    : .OpenReport(sReportName, Access.AcView.acViewPreview)
    : End If
    :
    : End With
    : Else
    : With acApp.DoCmd
    : .OpenReport(sReportName, Access.AcView.acViewPreview)
    :
    : End With
    :
    : End If
    : ' Print the report.
    : StrFileName = Mid(sUserName, 1, InStr(1, sUserName, "@", CompareMethod.Text) - 1) & sReportName & ".snp"
    : 'if it is already there, delete it
    : .DoCmd.OutputTo(Access.AcOutputObjectType.acOutputReport, , acFormatSNP, StrFilePath & StrFileName)
    : End With
    :
    :
    : acApp.Quit()
    : acApp = Nothing
    :
    : Response.Redirect(StrFilePath & StrFileName, False)
    :
    : End Function
    :
    :
    :
    :

    [red]Good luck![/red]
    [blue]Hackman[/blue]

Sign In or Register to comment.