Hi Villeroy
Thanks for replying!
Ok, My problem is that actually I have to test some data in the dialog (UserName Password present; UserName, Password valid) if OK is pressed and only to leave dialog if I have valid data or if Cancel is pressed.
Also worth knowing is that these errors only show if the application is called when opening the document.
(Creating the dialog was my first foray into macros… so I was still learning … Here is the code below, warts and all)
Sub ShowLoginDialog
On Error GoTo ErrorHandler
’ oDialog As Object is declared outside the subroutine
Dim oDialogLibrary As Object
Dim oDialogModel As Object
Dim oTextField1 As Object
Dim oTextField1Model as Object
Dim oTextField2 As Object
Dim oButtonOK As Object
Dim oButtonCancel As Object
With GlobalScope.BasicLibraries
If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
End With
' Get the dialog library
oDialogLibrary = GlobalScope.DialogLibraries.GetByName("Standard")
oDialog = Tools.ModuleControls.LoadDialog("Standard", "LoginDialog")
' Get controls (adjust names to match your dialog)
oTextField1 = oDialog.getControl("fld_UserName")
oTextField2 = oDialog.getControl("fld_Pwd")
oButtonOK = oDialog.getControl("btn_OK")
oButtonCancel = oDialog.getControl("btn_Cancel")
' Set initial values if needed, e.g.
' oTextField1.Text = ""
' Add event listeners
oButtonOK.addActionListener(CreateUnoListener("OKButtonClickHandler_", "com.sun.star.awt.XActionListener"))
oButtonCancel.addActionListener(CreateUnoListener("CancelButtonClickHandler_", "com.sun.star.awt.XActionListener"))
' Show the dialog
oDialog.execute()
' Dispose the dialog
' oDialog.dispose()
Exit Sub
ErrorHandler:
Reset
MsgBox “Error Encountered: All Files will be closed. [4]”, 0, “Error”
End Sub
Sub OKButtonClickHandler_actionPerformed(oEvent As Object)
On Error GoTo ErrorHandler
Dim oTextField1 AS Object
Dim oTextField2 As Object
With GlobalScope.BasicLibraries
If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
End With
oTextField1 = oDialog.getControl("fld_UserName")
oTextField2 = oDialog.getControl("fld_Pwd")
' Handle button click; MyName and MyPwd are global vars
MyName = oTextField1.Text
MyPwd = oTextField2.Text
IF LogMeIn(MyName, MyPwd) then
' Close the dialog
oDialog.endExecute
Else
MsgBox "Log in Failed, Please Try Again..."
End If
Exit Sub
ErrorHandler:
Resume Next
MsgBox “Error Encountered: All Files will be closed. [5]”, 0, “Error”
End Sub
Sub CancelButtonClickHandler_actionPerformed(oEvent As Object)
On Error GoTo ErrorHandler
' Handle button click
oDialog.endExecute
Exit Sub
ErrorHandler:
Resume Next
MsgBox “Error Encountered: All Files will be closed. [6]”, 0, “Error”
End Sub