Link to home
Start Free TrialLog in
Avatar of Jhovyn Marcos
Jhovyn Marcos

asked on

Sub or Function is not defined

Why am I getting an error "Sub or Function is not defined"...Here is my code

Form 2
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
     mvCn.Open

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

     Set rs = mvCn.Execute(strScript)

     Report.Database.SetDataSource rs
     Report.AutoSetUnboundFieldSource crBMTNameAndValue
    
     CRViewer1.ReportSource = Report
     CRViewer1.ViewReport
    
     Set Report = Nothing

     End Function

Open in new window


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

Private Sub Command1_Click()

printReport

End Sub

Open in new window


The error message goes here "Private Sub Command1_Click()"
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jhovyn Marcos
Jhovyn Marcos

ASKER

Thank you sir @Martin Liss..Now im getting an error "Operation is not allowed when the object is open"...I'm getting error here "mvCn.ConnectionString = strConnectionString"

Thank you again sir and God Bless!
It is owing to relevant Sub or Function not matched (or put properly).
Now im getting an error "Operation is not allowed when the object is open"

That should be a new question.
I'm glad I was able to help.

If you expand the “Full Biography” section of my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015 and 2016
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2016