Sub or Function is not defined

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jhovyn
    New Member
    • Feb 2017
    • 2

    Sub or Function is not defined

    Why am I getting an error "Sub or Function is not defined"...Here is my code
    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
         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
    Form 1.....Call my function "printRepor t" here
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    
    printReport
    
    End Sub
    The error message goes here "Private Sub Command1_Click( )"
  • PhilOfWalton
    Recognized Expert Top Contributor
    • Mar 2016
    • 1430

    #2
    I'm guessing.

    1 Try Call PrintReport in your Sub Command1_Click

    2 Are there any controls on your form called "PrintRepor t"?

    Phil

    Comment

    • jhovyn
      New Member
      • Feb 2017
      • 2

      #3
      Oh I forgot something..My printReport Function is defined in "Form2"

      Comment

      Working...