I want the form to open with one of the months pre-selected. The pre-selected month will be the one I last chose.
I already have the combobox filled from a table containing all 12 months. I also have a table with the last selected monthname. I have written a macro which goes to the MonthSelected table, extracts the value and sets the value into the combobox, however, I cannot get it to run as the form starts up. I can get it to run correctly by pressing a pushbutton with the "Mouse Button Pressed" event set to my macro.
Code: Select all
REM
Sub MainMenu_Initialize(evt as Object)
REM Create an object to store the results
dim rows
rows = createUnoService("com.sun.star.sdb.RowSet")
REM Need a reference to our current database
Dim frm As object
frm = evt.Source.Model.Parent
' frm = thisComponent.CurrentController.Frame
REM get the connection for the database
rows.ActiveConnection = ThisComponent.Parent.DataSource.getConnection("","")
REM Set the command type, create an sql statement, and execute it
rows.CommandType = com.sun.star.sdb.CommandType.COMMAND
rows.Command = "select ""MonthNo"", ""MonthName"" from ""SelectedMonth"""
rows.execute()
REM Do something with the data
dim MonthNo, MonthName
while rows.next()
MonthNo = rows.getInt(1)
MonthName = rows.getString(2)
wend
' Print MonthName
Dim ComboBox As Object
ComboBox=Evt.Source.Model.Parent.getByName("CurrentMonth")
ComboBox.Text = MonthName
End Sub
Can anyone suggest how this can be achieved.
Thanks