Hi everyone
With great help from Ratslinger I learned a bi t while instituting a Macro (to send the current records to a report with the push of a button. But I came across another problem that is beyond me.
I have a few other buttons that launch various reports (also using macros). If I leave 1 macro at a time in my database the targeted buttons work fine. However when I put both macros in, one of them produces an error.
The first macro sends the current records to a report:
REM ***** BASIC *****
Option Explicit
Sub OpenReport
Dim oController As Object
Dim oReportDoc As Object
oController = ThisDatabaseDocument.currentController
if not oController.isconnected then oController.connect
oReportDoc = Thisdatabasedocument.reportdocuments.getbyname(“Email_Form”).open
End Sub
Sub PrintCurrent
Dim oForm As Object
Dim oColumn As Object
Dim iField As Integer
Dim oSubForm As Object
Dim oSubSubForm as Object
Dim oSubSubSubForm as Object
Dim oController As Object
Dim oReportDoc As Object
oForm = ThisComponent.Drawpage.Forms.getByName(“MainForm”)
oSubForm = oForm.getByName(“Contact”)
oSubsubform = osubform.getByName(“details”)
iField = osubsubForm.getByName(“txt-Res ID”).Text
if oForm.isNew() Then
MsgBox “New Record - Cannot Print”
Exit Sub
End If
oSubSubForm = oSubForm.getByName(“PrintForm”)
oColumn = osubSubForm.Columns.getByName(“res_id_fk”)
oColumn.updateInt(iField)
oSubSubForm.updateRow()
oController = ThisDatabaseDocument.currentController
if not oController.isconnected then oController.connect
oReportDoc = Thisdatabasedocument.reportdocuments.getbyname(“Email_Form”).open
End Sub
The second sends various buttons to certain reports
Sub PrintReport(oEvent)
Rem Get name of Control
sControlName = oEvent.source.Model.Name
Rem Check for button pushed
If sControlName = “btn1” Then
ReportName = “Party Order Form Today”
EndIf
If sControlName = “btn2” Then
ReportName = “Party Order Form By #”
EndIf
If sControlName = “btn3” Then
ReportName = “Party List”
EndIf
If sControlName = “btn4” Then
ReportName = “Tip List”
EndIf
If sControlName = “btn5” Then
ReportName = “Counter Weekly”
EndIf
If sControlName = “btn7” Then
ReportName = “Event Invoice”
EndIf
If sControlName = “btn8” Then
ReportName = “Email_Form”
EndIf
If sControlName = “btn9” Then
ReportName = “Corp Order E-Mail”
EndIf
If sControlName = “btn10” Then
ReportName = “Theme Email”
EndIf
If sControlName = “btn11” Then
ReportName= “specOinvoice”
EndIf
oContext = CreateUnoService(“com.sun.star.sdb.DatabaseContext”)
Rem set registered DB name here
oFont = oContext.getRegisteredObject(“Reservations JDBC”)
dbForms = oFont.DatabaseDocument.ReportDocuments
oAConnection = oFont.getConnection("","")
Dim pProp(1) As New com.sun.star.beans.PropertyValue
pProp(0).Name = “ActiveConnection”
pProp(0).Value = oAConnection
pProp(1).Name = “OpenMode”
pProp(1).Value = “open”
oForm = dbForms.loadComponentFromURL(ReportName, “_blank”, 0, pProp())
End Sub
When I put both macros in one after another I get a Variable Not Defined error on this line. What is the correction needed?
sControlName = oEvent.source.Model.Name
Thanks, Jody
W10, LO v7.1.2.2