Hi,
I have created a simple form that is called from a push button on sheet. Testing has shown me that if I put more than one push button on the form then the proper macros aren't triggered on the button press. The tests involved using other macro methods triggered by a single button on a copy of the current form - they all worked as expected, properly reading the input data and giving me message boxes for debugging purposes.
I also found that simply assigning the "Execute Action" wasn't enough, I also assigned the same action to "Key Released" and "Mouse Button Released". I figure this covers me if someone presses "enter" while the button is selected.
The form looks like this:

And in the design area:
The “Add Player” button has the “Button Type” of “OK” and the “Cancel” button has the “Button Type” of “Cancel”
The idea is to have a button that people can use to back out if they do something like launch the wrong form, or the macro that processes the form tells them that the data they are trying to enter is already there. This is simply the first in a series of forms I want to create to insert data into a spreadsheet for the purposes of managing a pool team and it's finances. While I could do this as a database and some perl/c/ code easily the other purpose is to have a calc template that can be distributed to other people for them to use.
For now the action macro just creates a new sheet, once I get it working properly there is more that it will do.
The macro code for launching and reading the form is:
Global Continue as Boolean
Dim Add_Player_Dlg As Object
Sub Start_City_Player_Input()
Add_Player_Dlg = CreateUnoDialog(DialogLibraries.Standard.City_Player_Input)
Add_Player_Dlg.Execute()
End Sub
Sub Read_City_Player_Input()
DIM oDoc as Object
DIM oSheets as Object
Dim SheetNotExist as Boolean
Dim SheetCount as Integer
DIM NewSheetNum as Integer
Dim First_Name as String
DIM Last_Name as String
DIM NewSheetName as String
SheetNotExist = True
oDoc = ThisComponent
oSheets = oDoc.Sheets
' Set Sheet Count and number for new sheet
SheetCount = oSheets.Count
NewSheetNum = SheetCount + 1
First_Name = Add_Player_Dlg.getControl("FirstName").getText()
Last_Name = Add_Player_Dlg.getControl("LastName").getText()
Space = " "
' Check a value has been entered
If isNull(First_Name) And isNull(Last_Name) Then
' No Data raise error
MsgBox("Please Enter a First Name and/or a Last Name", MB_OK, "Error")
ElseIf Not isNull(FirstName) And Not isNull(Last_Name) Then
' Concatenate into new name for sheet
NewSheetName = First_Name & Space & Last_Name
MsgBox(NewSheetName, MB_OK, "Debug")
ElseIf isNull(First_Name) And Not isNull(Last_Name) Then
NewSheetName = Last_Name
MsgBox(NewSheetName, MB_OK, "Debug")
ElseIf Not isnull(First_Name) and isNull(Last_Name) Then
NewSheetName = First_Name
MsgBox(NewSheetName, MB_OK, "Debug")
Else
' No Data raise error
MsgBox("Please Enter a First Name and/or a Last Name", MB_OK, "Error")
End If
' Check if a sheet already has that name
Do While oSheets.hasByName(NewSheetName)
SheetNotExist = False
Loop
' If there is no sheet of that name create else raise error
If SheetNotExist Then
oSheets.insertNewByName(NewSheetName, NewSheetNum)
Add_Player_Clear
Else
'Raise error window
MsgBox("Player is already entered.", MB_OK, "Error")
End If
End Sub
' Clear any values stored in "Add Player" text fields and close the form
sub Add_Player_Clear()
Add_Player_Dlg.getByName("FirstName").Text = ""
Add_Player_Dlg.getByName("LastName").Text = ""
end Sub
Can anyone point me in the direction of what I am doing wrong, or the correct way to do this (it would seem silly if a form could only have one button on it).
