Why am I getting an error "Operation is not allowed when the object is open"....Here is my code

Option Explicit
Public Report As New CrystalReport1
Public mvCn As New ADODB.Connection

Public Function printReport()
Dim strConnectionString As String
Dim rs As ADODB.Recordset
Dim strScript As String
strConnectionString = "Provider=SQLOLEDB............"

mvCn.ConnectionString = strConnectionString
mvCn.CommandTimeout = 0
mvCn.CursorLocation = adUseClient

strScript = strScript & "SELECT * FROM employee" & vbCrLf

Set rs = mvCn.Execute(strScript)

Report.Database.SetDataSource rs
Report.AutoSetUnboundFieldSource crBMTNameAndValue

CRViewer1.ReportSource = Report

Set Report = Nothing

End Function

Form 1.....Call my function "printReport" here

Option Explicit
Private Sub Command1_Click()
End Sub

Im getting error here

mvCn.ConnectionString = strConnectionString
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.